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


Ignore:
Timestamp:
2011-01-09T23:24:53Z (15 years ago)
Author:
martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4b86dac
Parents:
3c106e88
Message:

partial networking stack overhaul

  • a lot of coding style changes (comments, indentation, etc.)
  • convert several ints to unsigned ints or size_t values
  • streamline many of the IPC-related macros (they no longer dereference the call structure by themselves)
  • get rid of netif_interface.h (containing only aliases for remote functions and not serving any purpose)
  • rename netif_local.{c|h} to netif_skel.{c|h} (it is really just a skeleton)
  • drop the "_remote" and "_standalone" suffixes from most of the netif_ functions (they do not serve any purpose anymore)
  • implement netif_client_connection() as a common framework function for all netif modules
    • update the lo module accordingly
  • ip module now reports the default gateway to the user whenever it is being set
File:
1 edited

Legend:

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

    r3c106e88 r774e6d1a  
    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
     
    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) {
     
    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.