Changeset f401312 in mainline for uspace/srv/net/il/ip/ip.c


Ignore:
Timestamp:
2011-01-14T12:34:42Z (13 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
45019865
Parents:
b2a6fcfe (diff), 6610565b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merged development into lelian/hidd

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/il/ip/ip.c

    rb2a6fcfe rf401312  
    275275        if (rc != EOK)
    276276                goto out;
    277         rc = add_module(NULL, &ip_globals.modules, ARP_NAME, ARP_FILENAME,
    278             SERVICE_ARP, 0, arp_connect_module);
     277        rc = add_module(NULL, &ip_globals.modules, (uint8_t *) ARP_NAME,
     278            (uint8_t *) ARP_FILENAME, SERVICE_ARP, 0, arp_connect_module);
    279279
    280280out:
     
    312312        measured_string_t names[] = {
    313313                {
    314                         (char *) "IPV",
     314                        (uint8_t *) "IPV",
    315315                        3
    316316                },
    317317                {
    318                         (char *) "IP_CONFIG",
     318                        (uint8_t *) "IP_CONFIG",
    319319                        9
    320320                },
    321321                {
    322                         (char *) "IP_ADDR",
     322                        (uint8_t *) "IP_ADDR",
    323323                        7
    324324                },
    325325                {
    326                         (char *) "IP_NETMASK",
     326                        (uint8_t *) "IP_NETMASK",
    327327                        10
    328328                },
    329329                {
    330                         (char *) "IP_GATEWAY",
     330                        (uint8_t *) "IP_GATEWAY",
    331331                        10
    332332                },
    333333                {
    334                         (char *) "IP_BROADCAST",
     334                        (uint8_t *) "IP_BROADCAST",
    335335                        12
    336336                },
    337337                {
    338                         (char *) "ARP",
     338                        (uint8_t *) "ARP",
    339339                        3
    340340                },
    341341                {
    342                         (char *) "IP_ROUTING",
     342                        (uint8_t *) "IP_ROUTING",
    343343                        10
    344344                }
     
    346346        measured_string_t *configuration;
    347347        size_t count = sizeof(names) / sizeof(measured_string_t);
    348         char *data;
     348        uint8_t *data;
    349349        measured_string_t address;
    350350        ip_route_t *route;
     
    368368        if (configuration) {
    369369                if (configuration[0].value)
    370                         ip_netif->ipv = strtol(configuration[0].value, NULL, 0);
    371 
    372                 ip_netif->dhcp = !str_lcmp(configuration[1].value, "dhcp",
     370                        ip_netif->ipv = strtol((char *) configuration[0].value, NULL, 0);
     371               
     372                ip_netif->dhcp = !str_lcmp((char *) configuration[1].value, "dhcp",
    373373                    configuration[1].length);
    374374               
     
    394394                        }
    395395                       
    396                         if ((inet_pton(AF_INET, configuration[2].value,
     396                        if ((inet_pton(AF_INET, (char *) configuration[2].value,
    397397                            (uint8_t *) &route->address.s_addr) != EOK) ||
    398                             (inet_pton(AF_INET, configuration[3].value,
     398                            (inet_pton(AF_INET, (char *) configuration[3].value,
    399399                            (uint8_t *) &route->netmask.s_addr) != EOK) ||
    400                             (inet_pton(AF_INET, configuration[4].value,
     400                            (inet_pton(AF_INET, (char *) configuration[4].value,
    401401                            (uint8_t *) &gateway.s_addr) == EINVAL) ||
    402                             (inet_pton(AF_INET, configuration[5].value,
     402                            (inet_pton(AF_INET, (char *) configuration[5].value,
    403403                            (uint8_t *) &ip_netif->broadcast.s_addr) == EINVAL))
    404404                            {
     
    441441        if (ip_netif->arp) {
    442442                if (route) {
    443                         address.value = (char *) &route->address.s_addr;
     443                        address.value = (uint8_t *) &route->address.s_addr;
    444444                        address.length = sizeof(in_addr_t);
    445445                       
     
    477477                ip_globals.gateway.gateway.s_addr = gateway.s_addr;
    478478                ip_globals.gateway.netif = ip_netif;
     479               
     480                char defgateway[INET_ADDRSTRLEN];
     481                inet_ntop(AF_INET, (uint8_t *) &gateway.s_addr,
     482                    defgateway, INET_ADDRSTRLEN);
     483                printf("%s: Default gateway (%s)\n", NAME, defgateway);
    479484        }
    480485
     
    9971002        measured_string_t destination;
    9981003        measured_string_t *translation;
    999         char *data;
     1004        uint8_t *data;
    10001005        int phone;
    10011006        int rc;
     
    10041009        if (netif->arp && (route->address.s_addr != dest.s_addr)) {
    10051010                destination.value = route->gateway.s_addr ?
    1006                     (char *) &route->gateway.s_addr : (char *) &dest.s_addr;
     1011                    (uint8_t *) &route->gateway.s_addr : (uint8_t *) &dest.s_addr;
    10071012                destination.length = sizeof(dest.s_addr);
    10081013
     
    10691074        int index;
    10701075        ip_route_t *route;
    1071 
     1076       
    10721077        if (!netif)
    10731078                return NULL;
    1074 
    1075         // start with the first one - the direct route
     1079       
     1080        /* Start with the first one (the direct route) */
    10761081        for (index = 0; index < ip_routes_count(&netif->routes); index++) {
    10771082                route = ip_routes_get_index(&netif->routes, index);
    1078                 if (route &&
     1083                if ((route) &&
    10791084                    ((route->address.s_addr & route->netmask.s_addr) ==
    1080                     (destination.s_addr & route->netmask.s_addr))) {
     1085                    (destination.s_addr & route->netmask.s_addr)))
    10811086                        return route;
    1082                 }
    10831087        }
    10841088
     
    12881292        if (device_id > 0) {
    12891293                netif = ip_netifs_find(&ip_globals.netifs, device_id);
    1290                 route = ip_netif_find_route(netif, * dest);
     1294                route = ip_netif_find_route(netif, *dest);
    12911295                if (netif && !route && (ip_globals.gateway.netif == netif))
    12921296                        route = &ip_globals.gateway;
     
    13181322                }
    13191323        }
    1320 
     1324       
    13211325        // if the local host is the destination
    13221326        if ((route->address.s_addr == dest->s_addr) &&
     
    15621566        socklen_t addrlen;
    15631567        int rc;
    1564 
     1568       
    15651569        header = (ip_header_t *) packet_get_data(packet);
    15661570        if (!header)
     
    15881592                return EINVAL;
    15891593        }
    1590 
     1594       
    15911595        // process ipopt and get destination
    15921596        dest = ip_get_destination(header);
     
    16091613        if (rc != EOK)
    16101614                return rc;
    1611 
     1615       
    16121616        route = ip_find_route(dest);
    16131617        if (!route) {
     
    17561760                    (header->destination_address & route->netmask.s_addr))) {
    17571761                        // clear the ARP mapping if any
    1758                         address.value = (char *) &header->destination_address;
     1762                        address.value = (uint8_t *) &header->destination_address;
    17591763                        address.length = sizeof(header->destination_address);
    17601764                        arp_clear_address_req(netif->arp->phone,
     
    18861890int
    18871891ip_message_standalone(ipc_callid_t callid, ipc_call_t *call, ipc_call_t *answer,
    1888     int *answer_count)
     1892    size_t *answer_count)
    18891893{
    18901894        packet_t *packet;
     
    19051909       
    19061910        case IPC_M_CONNECT_TO_ME:
    1907                 return ip_register(IL_GET_PROTO(call), IL_GET_SERVICE(call),
    1908                     IPC_GET_PHONE(call), NULL);
     1911                return ip_register(IL_GET_PROTO(*call), IL_GET_SERVICE(*call),
     1912                    IPC_GET_PHONE(*call), NULL);
    19091913       
    19101914        case NET_IL_DEVICE:
    1911                 return ip_device_req_local(0, IPC_GET_DEVICE(call),
    1912                     IPC_GET_SERVICE(call));
     1915                return ip_device_req_local(0, IPC_GET_DEVICE(*call),
     1916                    IPC_GET_SERVICE(*call));
    19131917       
    19141918        case NET_IL_SEND:
    19151919                rc = packet_translate_remote(ip_globals.net_phone, &packet,
    1916                     IPC_GET_PACKET(call));
     1920                    IPC_GET_PACKET(*call));
    19171921                if (rc != EOK)
    19181922                        return rc;
    1919                 return ip_send_msg_local(0, IPC_GET_DEVICE(call), packet, 0,
    1920                     IPC_GET_ERROR(call));
     1923                return ip_send_msg_local(0, IPC_GET_DEVICE(*call), packet, 0,
     1924                    IPC_GET_ERROR(*call));
    19211925       
    19221926        case NET_IL_DEVICE_STATE:
    1923                 return ip_device_state_message(IPC_GET_DEVICE(call),
    1924                     IPC_GET_STATE(call));
     1927                return ip_device_state_message(IPC_GET_DEVICE(*call),
     1928                    IPC_GET_STATE(*call));
    19251929       
    19261930        case NET_IL_RECEIVED:
    19271931                rc = packet_translate_remote(ip_globals.net_phone, &packet,
    1928                     IPC_GET_PACKET(call));
     1932                    IPC_GET_PACKET(*call));
    19291933                if (rc != EOK)
    19301934                        return rc;
    1931                 return ip_receive_message(IPC_GET_DEVICE(call), packet);
     1935                return ip_receive_message(IPC_GET_DEVICE(*call), packet);
    19321936       
    19331937        case NET_IP_RECEIVED_ERROR:
    19341938                rc = packet_translate_remote(ip_globals.net_phone, &packet,
    1935                     IPC_GET_PACKET(call));
     1939                    IPC_GET_PACKET(*call));
    19361940                if (rc != EOK)
    19371941                        return rc;
    1938                 return ip_received_error_msg_local(0, IPC_GET_DEVICE(call),
    1939                     packet, IPC_GET_TARGET(call), IPC_GET_ERROR(call));
     1942                return ip_received_error_msg_local(0, IPC_GET_DEVICE(*call),
     1943                    packet, IPC_GET_TARGET(*call), IPC_GET_ERROR(*call));
    19401944       
    19411945        case NET_IP_ADD_ROUTE:
    1942                 return ip_add_route_req_local(0, IPC_GET_DEVICE(call),
    1943                     IP_GET_ADDRESS(call), IP_GET_NETMASK(call),
    1944                     IP_GET_GATEWAY(call));
     1946                return ip_add_route_req_local(0, IPC_GET_DEVICE(*call),
     1947                    IP_GET_ADDRESS(*call), IP_GET_NETMASK(*call),
     1948                    IP_GET_GATEWAY(*call));
    19451949
    19461950        case NET_IP_SET_GATEWAY:
    1947                 return ip_set_gateway_req_local(0, IPC_GET_DEVICE(call),
    1948                     IP_GET_GATEWAY(call));
     1951                return ip_set_gateway_req_local(0, IPC_GET_DEVICE(*call),
     1952                    IP_GET_GATEWAY(*call));
    19491953
    19501954        case NET_IP_GET_ROUTE:
     
    19541958                        return rc;
    19551959               
    1956                 rc = ip_get_route_req_local(0, IP_GET_PROTOCOL(call), addr,
     1960                rc = ip_get_route_req_local(0, IP_GET_PROTOCOL(*call), addr,
    19571961                    (socklen_t) addrlen, &device_id, &header, &headerlen);
    19581962                if (rc != EOK)
    19591963                        return rc;
    19601964               
    1961                 IPC_SET_DEVICE(answer, device_id);
    1962                 IP_SET_HEADERLEN(answer, headerlen);
     1965                IPC_SET_DEVICE(*answer, device_id);
     1966                IP_SET_HEADERLEN(*answer, headerlen);
    19631967               
    19641968                *answer_count = 2;
     
    19721976       
    19731977        case NET_IL_PACKET_SPACE:
    1974                 rc = ip_packet_size_message(IPC_GET_DEVICE(call), &addrlen,
     1978                rc = ip_packet_size_message(IPC_GET_DEVICE(*call), &addrlen,
    19751979                    &prefix, &content, &suffix);
    19761980                if (rc != EOK)
    19771981                        return rc;
    19781982               
    1979                 IPC_SET_ADDR(answer, addrlen);
    1980                 IPC_SET_PREFIX(answer, prefix);
    1981                 IPC_SET_CONTENT(answer, content);
    1982                 IPC_SET_SUFFIX(answer, suffix);
     1983                IPC_SET_ADDR(*answer, addrlen);
     1984                IPC_SET_PREFIX(*answer, prefix);
     1985                IPC_SET_CONTENT(*answer, content);
     1986                IPC_SET_SUFFIX(*answer, suffix);
    19831987                *answer_count = 4;
    19841988                return EOK;
    19851989       
    19861990        case NET_IL_MTU_CHANGED:
    1987                 return ip_mtu_changed_message(IPC_GET_DEVICE(call),
    1988                     IPC_GET_MTU(call));
     1991                return ip_mtu_changed_message(IPC_GET_DEVICE(*call),
     1992                    IPC_GET_MTU(*call));
    19891993        }
    19901994       
     
    20072011        while (true) {
    20082012                ipc_call_t answer;
    2009                 int answer_count;
     2013                size_t count;
    20102014               
    20112015                /* Clear the answer structure */
    2012                 refresh_answer(&answer, &answer_count);
     2016                refresh_answer(&answer, &count);
    20132017               
    20142018                /* Fetch the next message */
     
    20182022                /* Process the message */
    20192023                int res = il_module_message_standalone(callid, &call, &answer,
    2020                     &answer_count);
     2024                    &count);
    20212025               
    20222026                /*
     
    20302034               
    20312035                /* Answer the message */
    2032                 answer_call(callid, res, &answer, answer_count);
     2036                answer_call(callid, res, &answer, count);
    20332037        }
    20342038}
Note: See TracChangeset for help on using the changeset viewer.