~as-s/helenos/ipv6

« back to all changes in this revision

Viewing changes to uspace/srv/net/udp/assoc.c

  • Committer: Anthony Steinhauser
  • Date: 2013-07-08 01:07:36 UTC
  • Revision ID: as@strmilov.cz-20130708010736-pbvrszhamp0v64ez
HelenOS networking stack supports IPv6

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * Copyright (c) 2012 Jiri Svoboda
 
3
 * Copyright (c) 2013 Antonin Steinhauser
3
4
 * All rights reserved.
4
5
 *
5
6
 * Redistribution and use in source and binary forms, with or without
38
39
#include <stdbool.h>
39
40
#include <fibril_synch.h>
40
41
#include <io/log.h>
 
42
#include <inet/inet.h>
41
43
#include <stdlib.h>
42
44
 
43
45
#include "assoc.h"
250
252
        if (fsock != NULL)
251
253
                sp.foreign = *fsock;
252
254
 
253
 
        if (sp.foreign.addr.s_addr == INADDR_ANY || sp.foreign.port == 0)
 
255
        if (in6addr_equal(&sp.foreign.addr, &in6addr_any) ||
 
256
            in6addr_equal(&sp.foreign.addr, &in6addr_any) ||
 
257
            sp.foreign.port == 0)
254
258
                return EINVAL;
255
259
 
 
260
        if (in6addr_equal(&sp.local.addr, &in6addr_any) ||
 
261
            in6addr_equal(&sp.local.addr, &in4addr_any)) {
 
262
                int rc = inet_get_srcaddr(&sp.foreign.addr, 0, &sp.local.addr);
 
263
                if (rc != EOK)
 
264
                        return rc;
 
265
        }
 
266
 
256
267
        rc = udp_pdu_encode(&sp, msg, &pdu);
257
268
        if (rc != EOK)
258
269
                return ENOMEM;
369
380
/** Match socket with pattern. */
370
381
static bool udp_socket_match(udp_sock_t *sock, udp_sock_t *patt)
371
382
{
372
 
        log_msg(LOG_DEFAULT, LVL_DEBUG, "udp_socket_match(sock=(%x,%u), pat=(%x,%u))",
373
 
            sock->addr.s_addr, sock->port, patt->addr.s_addr, patt->port);
 
383
        log_msg(LOG_DEFAULT, LVL_DEBUG,
 
384
            "udp_socket_match(sock=(%u), pat=(%u))", sock->port, patt->port);
374
385
 
375
 
        if (patt->addr.s_addr != INADDR_ANY &&
376
 
            patt->addr.s_addr != sock->addr.s_addr)
 
386
        if (!in6addr_equal(&patt->addr, &in6addr_any) &&
 
387
            !in6addr_equal(&patt->addr, &sock->addr) &&
 
388
            (!in6addr_equal(&patt->addr, &in4addr_any) ||
 
389
            !is_mapped(&sock->addr)))
377
390
                return false;
378
391
 
379
392
        if (patt->port != UDP_PORT_ANY &&
419
432
        list_foreach(assoc_list, link) {
420
433
                udp_assoc_t *assoc = list_get_instance(link, udp_assoc_t, link);
421
434
                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.s_addr, asp->foreign.port,
424
 
                    asp->local.addr.s_addr, asp->local.port);
 
435
                log_msg(LOG_DEFAULT, LVL_DEBUG, "compare with assoc (f:(%u), l:(%u))",
 
436
                    asp->foreign.port, asp->local.port);
425
437
 
426
438
                /* Skip unbound associations */
427
439
                if (asp->local.port == UDP_PORT_ANY)