Changeset 19a4f73 in mainline


Ignore:
Timestamp:
2013-06-20T15:21:48Z (11 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a2e3ee6
Parents:
3e66428
Message:

udp: use new network address infrastructure (towards IPv6 support)

Location:
uspace
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/inet.c

    r3e66428 r19a4f73  
    144144}
    145145
     146int inet2_get_srcaddr(inet2_addr_t *remote, uint8_t tos, inet2_addr_t *local)
     147{
     148        uint32_t remote_addr;
     149        int rc = inet2_addr_pack(remote, &remote_addr);
     150        if (rc != EOK)
     151                return rc;
     152       
     153        async_exch_t *exch = async_exchange_begin(inet_sess);
     154       
     155        sysarg_t local_addr;
     156        rc = async_req_2_1(exch, INET_GET_SRCADDR, (sysarg_t) remote_addr,
     157            tos, &local_addr);
     158       
     159        async_exchange_end(exch);
     160       
     161        if (rc != EOK)
     162                return rc;
     163       
     164        inet2_addr_unpack(local_addr, local);
     165        return EOK;
     166}
     167
    146168static void inet_ev_recv(ipc_callid_t callid, ipc_call_t *call)
    147169{
  • uspace/lib/c/generic/inet/addr2.c

    r3e66428 r19a4f73  
    4040#include <stdio.h>
    4141
     42// TODO temporarily
     43#include <assert.h>
     44
     45static inet2_addr_t inet2_addr_any = {
     46        .family = AF_INET,
     47        .addr = {0, 0, 0, 0}
     48};
     49
     50static inet2_addr_t inet2_addr6_any = {
     51        .family = AF_INET6,
     52        .addr = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
     53};
     54
    4255/** Parse network address family.
    4356 *
     
    336349}
    337350
    338 int inet2_addr_is_empty(inet2_addr_t *addr)
    339 {
    340         return (addr->family == 0);
     351int inet2_addr_is_any(inet2_addr_t *addr)
     352{
     353        return ((addr->family == 0) ||
     354            (inet2_addr_compare(addr, &inet2_addr_any)) ||
     355            (inet2_addr_compare(addr, &inet2_addr6_any)));
     356}
     357
     358void inet_inet2(inet_addr_t *addr, inet2_addr_t *addr2)
     359{
     360        // TODO temporarily
     361        inet2_addr_unpack(addr->ipv4, addr2);
     362}
     363
     364void inet2_inet(inet2_addr_t *addr2, inet_addr_t *addr)
     365{
     366        // TODO temporarily
     367        assert(addr2->family == AF_INET);
     368        inet2_addr_pack(addr2, &addr->ipv4);
    341369}
    342370
  • uspace/lib/c/include/inet/addr2.h

    r3e66428 r19a4f73  
    3838#include <stdint.h>
    3939#include <net/in.h>
     40#include <inet/addr.h>
    4041
    4142#define INET2_ADDR_SIZE  16
     
    8485
    8586extern int inet2_addr_compare(inet2_addr_t *, inet2_addr_t *);
    86 extern int inet2_addr_is_empty(inet2_addr_t *);
     87extern int inet2_addr_is_any(inet2_addr_t *);
     88
     89extern void inet_inet2(inet_addr_t *, inet2_addr_t *);
     90extern void inet2_inet(inet2_addr_t *, inet_addr_t *);
    8791
    8892#endif
  • uspace/lib/c/include/inet/inet.h

    r3e66428 r19a4f73  
    3737
    3838#include <inet/addr.h>
     39#include <inet/addr2.h>
    3940#include <sys/types.h>
    4041
     
    6061extern int inet_send(inet_dgram_t *, uint8_t, inet_df_t);
    6162extern int inet_get_srcaddr(inet_addr_t *, uint8_t, inet_addr_t *);
     63extern int inet2_get_srcaddr(inet2_addr_t *, uint8_t, inet2_addr_t *);
    6264
    6365#endif
  • uspace/lib/c/include/net/in.h

    r3e66428 r19a4f73  
    4747#define INADDR_ANY 0
    4848
    49 /** Type definition of the INET address.
    50  * @see in_addr
    51  */
    52 typedef struct in_addr in_addr_t;
    53 
    54 /** Type definition of the INET socket address.
    55  * @see sockaddr_in
    56  */
    57 typedef struct sockaddr_in      sockaddr_in_t;
    58 
    5949/** INET address. */
    60 struct in_addr {
     50typedef struct in_addr {
    6151        /** 4 byte IP address. */
    6252        uint32_t s_addr;
    63 };
     53} in_addr_t;
    6454
    6555/** INET socket address.
    6656 * @see sockaddr
    6757 */
    68 struct sockaddr_in {
     58typedef struct sockaddr_in {
    6959        /** Address family. Should be AF_INET. */
    7060        uint16_t sin_family;
     
    7262        uint16_t sin_port;
    7363        /** Internet address. */
    74         struct in_addr sin_addr;
     64        in_addr_t sin_addr;
    7565        /** Padding to meet the sockaddr size. */
    7666        uint8_t sin_zero[8];
    77 };
     67} sockaddr_in_t;
    7868
    7969#endif
  • uspace/lib/c/include/net/ip_protocols.h

    r3e66428 r19a4f73  
    4444/*@{*/
    4545
    46 #define IPPROTO_ICMP    1
    47 #define IPPROTO_TCP     6
    48 #define IPPROTO_UDP     17
     46#define IPPROTO_ICMP    1
     47#define IPPROTO_TCP     6
     48#define IPPROTO_UDP     17
     49#define IPPROTO_ICMPV6  58
    4950
    5051/*@}*/
  • uspace/srv/net/udp/assoc.c

    r3e66428 r19a4f73  
    8282        if (lsock != NULL)
    8383                assoc->ident.local = *lsock;
     84       
    8485        if (fsock != NULL)
    8586                assoc->ident.foreign = *fsock;
     
    251252                sp.foreign = *fsock;
    252253
    253         if (sp.foreign.addr.ipv4 == 0 || sp.foreign.port == 0)
     254        if ((inet2_addr_is_any(&sp.foreign.addr)) ||
     255            (sp.foreign.port == UDP_PORT_ANY))
    254256                return EINVAL;
    255257
     
    370372static bool udp_socket_match(udp_sock_t *sock, udp_sock_t *patt)
    371373{
    372         log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_socket_match(sock=(%x,%u), pat=(%x,%u))",
    373             sock->addr.ipv4, sock->port, patt->addr.ipv4, patt->port);
    374 
    375         if (patt->addr.ipv4 != UDP_IPV4_ANY &&
    376             patt->addr.ipv4 != sock->addr.ipv4)
     374        if ((!inet2_addr_is_any(&patt->addr)) &&
     375            (!inet2_addr_compare(&patt->addr, &sock->addr)))
    377376                return false;
    378 
    379         if (patt->port != UDP_PORT_ANY &&
    380             patt->port != sock->port)
     377       
     378        if ((patt->port != UDP_PORT_ANY) &&
     379            (patt->port != sock->port))
    381380                return false;
    382 
     381       
    383382        log_msg(LOG_DEFAULT, LVL_DEBUG, " -> match");
    384 
     383       
    385384        return true;
    386385}
     
    414413{
    415414        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_assoc_find_ref(%p)", sp);
    416 
     415       
    417416        fibril_mutex_lock(&assoc_list_lock);
    418 
     417       
    419418        list_foreach(assoc_list, link) {
    420419                udp_assoc_t *assoc = list_get_instance(link, udp_assoc_t, link);
    421420                udp_sockpair_t *asp = &assoc->ident;
    422                 log_msg(LOG_DEFAULT, LVL_DEBUG, "compare with assoc (f:(%x,%u), l:(%x,%u))",
    423                     asp->foreign.addr.ipv4, asp->foreign.port,
    424                     asp->local.addr.ipv4, asp->local.port);
    425 
     421               
    426422                /* Skip unbound associations */
    427423                if (asp->local.port == UDP_PORT_ANY)
    428424                        continue;
    429 
     425               
    430426                if (udp_sockpair_match(sp, asp)) {
    431427                        log_msg(LOG_DEFAULT, LVL_DEBUG, "Returning assoc %p", assoc);
     
    435431                }
    436432        }
    437 
     433       
    438434        fibril_mutex_unlock(&assoc_list_lock);
    439435        return NULL;
  • uspace/srv/net/udp/pdu.c

    r3e66428 r19a4f73  
    8686static void udp_phdr_setup(udp_pdu_t *pdu, udp_phdr_t *phdr)
    8787{
    88         phdr->src_addr = host2uint32_t_be(pdu->src.ipv4);
    89         phdr->dest_addr = host2uint32_t_be(pdu->dest.ipv4);
     88        // FIXME: Check for correctness
     89       
     90        uint32_t src;
     91        inet2_addr_pack(&pdu->src, &src);
     92       
     93        uint32_t dest;
     94        inet2_addr_pack(&pdu->dest, &dest);
     95       
     96        phdr->src_addr = host2uint32_t_be(src);
     97        phdr->dest_addr = host2uint32_t_be(dest);
    9098        phdr->zero = 0;
    9199        phdr->protocol = IP_PROTO_UDP;
  • uspace/srv/net/udp/sock.c

    r3e66428 r19a4f73  
    199199        }
    200200
    201         socket = (udp_sockdata_t *)sock_core->specific_data;
    202 
    203         fsock.addr.ipv4 = uint32_t_be2host(addr->sin_addr.s_addr);
     201        socket = (udp_sockdata_t *) sock_core->specific_data;
     202       
     203        inet2_addr_unpack(uint32_t_be2host(addr->sin_addr.s_addr),
     204            &fsock.addr);
    204205        fsock.port = sock_core->port;
    205206        urc = udp_uc_set_local(socket->assoc, &fsock);
     
    269270                }
    270271               
    271                 fsock.addr.ipv4 = uint32_t_be2host(addr->sin_addr.s_addr);
     272                inet2_addr_unpack(uint32_t_be2host(addr->sin_addr.s_addr),
     273                    &fsock.addr);
    272274                fsock.port = uint16_t_be2host(addr->sin_port);
    273275                fsock_ptr = &fsock;
     
    314316        fibril_mutex_lock(&socket->lock);
    315317       
    316         if (socket->assoc->ident.local.addr.ipv4 == UDP_IPV4_ANY) {
     318        if (inet2_addr_is_any(&socket->assoc->ident.local.addr)) {
    317319                /* Determine local IP address */
    318                 inet_addr_t loc_addr, rem_addr;
    319                
    320                 rem_addr.ipv4 = fsock_ptr ? fsock.addr.ipv4 :
    321                     socket->assoc->ident.foreign.addr.ipv4;
    322                
    323                 int rc = inet_get_srcaddr(&rem_addr, 0, &loc_addr);
     320                inet2_addr_t loc_addr;
     321                inet2_addr_t rem_addr;
     322               
     323                rem_addr = fsock_ptr ? fsock.addr :
     324                    socket->assoc->ident.foreign.addr;
     325               
     326                int rc = inet2_get_srcaddr(&rem_addr, 0, &loc_addr);
    324327                if (rc != EOK) {
    325328                        fibril_mutex_unlock(&socket->lock);
     
    330333                }
    331334               
    332                 socket->assoc->ident.local.addr.ipv4 = loc_addr.ipv4;
    333                 log_msg(LOG_DEFAULT, LVL_DEBUG, "Local IP address is %x",
    334                     socket->assoc->ident.local.addr.ipv4);
     335                socket->assoc->ident.local.addr = loc_addr;
    335336        }
    336337       
     
    410411        size_t data_len;
    411412        udp_error_t urc;
    412         udp_sock_t rsock;
     413        udp_sock_t *rsock;
    413414        struct sockaddr_in addr;
    414415        int rc;
     
    446447        log_msg(LOG_DEFAULT, LVL_DEBUG, "Got data in sock recv_buffer");
    447448
    448         rsock = socket->recv_fsock;
     449        rsock = &socket->recv_fsock;
    449450        data_len = socket->recv_buffer_used;
    450451        urc = socket->recv_error;
     
    476477
    477478        if (IPC_GET_IMETHOD(call) == NET_SOCKET_RECVFROM) {
    478                 /* Fill addr */
     479                /* Fill address */
     480                uint32_t rsock_addr;
     481                int rc = inet2_addr_pack(&rsock->addr, &rsock_addr);
     482                if (rc != EOK) {
     483                        fibril_mutex_unlock(&socket->recv_buffer_lock);
     484                        fibril_mutex_unlock(&socket->lock);
     485                        async_answer_0(callid, rc);
     486                        return;
     487                }
     488               
    479489                addr.sin_family = AF_INET;
    480                 addr.sin_addr.s_addr = host2uint32_t_be(rsock.addr.ipv4);
    481                 addr.sin_port = host2uint16_t_be(rsock.port);
     490                addr.sin_addr.s_addr = host2uint32_t_be(rsock_addr);
     491                addr.sin_port = host2uint16_t_be(rsock->port);
    482492
    483493                log_msg(LOG_DEFAULT, LVL_DEBUG, "addr read receive");
  • uspace/srv/net/udp/udp_inet.c

    r3e66428 r19a4f73  
    6666        pdu->data = dgram->data;
    6767        pdu->data_size = dgram->size;
    68 
    69         pdu->src.ipv4 = dgram->src.ipv4;
    70         pdu->dest.ipv4 = dgram->dest.ipv4;
    71         log_msg(LOG_DEFAULT, LVL_DEBUG, "src: 0x%08x, dest: 0x%08x",
    72             pdu->src.ipv4, pdu->dest.ipv4);
     68       
     69        inet_inet2(&dgram->src, &pdu->src);
     70        inet_inet2(&dgram->dest, &pdu->dest);
    7371
    7472        udp_received_pdu(pdu);
     
    8684        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_transmit_pdu()");
    8785
    88         dgram.src.ipv4 = pdu->src.ipv4;
    89         dgram.dest.ipv4 = pdu->dest.ipv4;
     86        inet2_inet(&pdu->src, &dgram.src);
     87        inet2_inet(&pdu->dest, &dgram.dest);
    9088        dgram.tos = 0;
    9189        dgram.data = pdu->data;
  • uspace/srv/net/udp/udp_type.h

    r3e66428 r19a4f73  
    4040#include <socket_core.h>
    4141#include <sys/types.h>
     42#include <inet/addr2.h>
    4243
    4344#define UDP_FRAGMENT_SIZE 4096
     
    5758
    5859typedef enum {
    59         XF_DUMMY        = 0x1
     60        XF_DUMMY = 0x1
    6061} xflags_t;
    61 
    62 typedef struct {
    63         uint32_t ipv4;
    64 } netaddr_t;
    65 
    66 enum netaddr {
    67         UDP_IPV4_ANY = 0
    68 };
    6962
    7063enum udp_port {
     
    7366
    7467typedef struct {
    75         netaddr_t addr;
     68        inet2_addr_t addr;
    7669        uint16_t port;
    7770} udp_sock_t;
     
    9386typedef struct {
    9487        /** Source address */
    95         netaddr_t src;
     88        inet2_addr_t src;
    9689        /** Destination address */
    97         netaddr_t dest;
    98 
     90        inet2_addr_t dest;
     91       
    9992        /** Encoded PDU data including header */
    10093        void *data;
Note: See TracChangeset for help on using the changeset viewer.