diff options
author | Ondrej Zajicek <santiago@crfreenet.org> | 2014-02-06 17:46:01 +0100 |
---|---|---|
committer | Ondrej Zajicek <santiago@crfreenet.org> | 2014-02-06 17:46:01 +0100 |
commit | 48e5f32db676645640f84ab3d630cce975aa6b20 (patch) | |
tree | b940fc8156b3e0c18aab6c339a066bdb7a9ec1e0 /lib | |
parent | f48fa14214301382b2e6b134788a7506b61b664f (diff) |
Many changes in I/O and OSPF sockets and packet handling.
I/O:
- BSD: specify src addr on IP sockets by IP_HDRINCL
- BSD: specify src addr on UDP sockets by IP_SENDSRCADDR
- Linux: specify src addr on IP/UDP sockets by IP_PKTINFO
- IPv6: specify src addr on IP/UDP sockets by IPV6_PKTINFO
- Alternative SKF_BIND flag for binding to IP address
- Allows IP/UDP sockets without tx_hook, on these
sockets a packet is discarded when TX queue is full
- Use consistently SOL_ for socket layer values.
OSPF:
- Packet src addr is always explicitly set
- Support for secondary addresses in BSD
- Dynamic RX/TX buffers
- Fixes some minor buffer overruns
- Interface option 'tx length'
- Names for vlink pseudoifaces (vlinkX)
- Vlinks use separate socket for TX
- Vlinks do not use fixed associated iface
- Fixes TTL for direct unicast packets
- Fixes DONTROUTE for OSPF sockets
- Use ifa->ifname instead of ifa->iface->name
Diffstat (limited to 'lib')
-rw-r--r-- | lib/resource.c | 17 | ||||
-rw-r--r-- | lib/socket.h | 18 |
2 files changed, 26 insertions, 9 deletions
diff --git a/lib/resource.c b/lib/resource.c index bf4b3ae9..64f9a39c 100644 --- a/lib/resource.c +++ b/lib/resource.c @@ -157,13 +157,13 @@ rfree(void *res) { resource *r = res; - if (r) - { - if (r->n.next) - rem_node(&r->n); - r->class->free(r); - xfree(r); - } + if (!r) + return; + + if (r->n.next) + rem_node(&r->n); + r->class->free(r); + xfree(r); } /** @@ -408,6 +408,9 @@ mb_realloc(void *m, unsigned size) void mb_free(void *m) { + if (!m) + return; + struct mblock *b = SKIP_BACK(struct mblock, data, m); rfree(b); } diff --git a/lib/socket.h b/lib/socket.h index 780d596b..894d5561 100644 --- a/lib/socket.h +++ b/lib/socket.h @@ -57,6 +57,9 @@ int sk_open(sock *); /* Open socket */ int sk_send(sock *, unsigned len); /* Send data, <0=err, >0=ok, 0=sleep */ int sk_send_to(sock *, unsigned len, ip_addr to, unsigned port); /* sk_send to given destination */ void sk_reallocate(sock *); /* Free and allocate tbuf & rbuf */ +void sk_set_rbsize(sock *s, uint val); /* Resize RX buffer */ +void sk_set_tbsize(sock *s, uint val); /* Resize TX buffer, keeping content */ +void sk_set_tbuf(sock *s, void *tbuf); /* Switch TX buffer, NULL-> return to internal */ void sk_dump_all(void); int sk_set_ttl(sock *s, int ttl); /* Set transmit TTL for given socket */ int sk_set_min_ttl(sock *s, int ttl); /* Set minimal accepted TTL for given socket */ @@ -89,10 +92,13 @@ extern int sk_priority_control; /* Suggested priority for control traffic, shoul #define SKF_V6ONLY 1 /* Use IPV6_V6ONLY socket option */ #define SKF_LADDR_RX 2 /* Report local address for RX packets */ -#define SKF_LADDR_TX 4 /* Allow to specify local address for TX packets */ -#define SKF_TTL_RX 8 /* Report TTL / Hop Limit for RX packets */ +#define SKF_TTL_RX 4 /* Report TTL / Hop Limit for RX packets */ +#define SKF_BIND 8 /* Bind datagram socket to given source address */ #define SKF_THREAD 0x100 /* Socked used in thread, Do not add to main loop */ +#define SKF_TRUNCATED 0x200 /* Received packet was truncated, set by IO layer */ +#define SKF_HDRINCL 0x400 /* Used internally */ +#define SKF_PKTINFO 0x800 /* Used internally */ /* * Socket types SA SP DA DP IF TTL SendTo (?=may, -=must not, *=must) @@ -118,6 +124,14 @@ extern int sk_priority_control; /* Suggested priority for control traffic, shoul * call sk_setup_multicast() to enable multicast on that socket, * and then use sk_join_group() and sk_leave_group() to manage * a set of received multicast groups. + * + * For datagram (SK_UDP, SK_IP) sockets, there are two ways to handle + * source address. The socket could be bound to it using bind() + * syscall, but that also forbids the reception of multicast packets, + * or the address could be set on per-packet basis using platform + * dependent options (but these are not available in some corner + * cases). The first way is used when SKF_BIND is specified, the + * second way is used otherwise. */ #endif |