0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-11-17 08:38:42 +00:00

Use IP_PORTRANGE_HIGH for BFD where available

This commit is contained in:
Ondrej Zajicek 2015-02-22 20:14:14 +01:00
parent 6cf72d7ad7
commit 9c89560e6c
3 changed files with 13 additions and 6 deletions

View File

@ -103,6 +103,7 @@ extern int sk_priority_control; /* Suggested priority for control traffic, shou
#define SKF_LADDR_RX 0x04 /* Report local address for RX packets */ #define SKF_LADDR_RX 0x04 /* Report local address for RX packets */
#define SKF_TTL_RX 0x08 /* Report TTL / Hop Limit for RX packets */ #define SKF_TTL_RX 0x08 /* Report TTL / Hop Limit for RX packets */
#define SKF_BIND 0x10 /* Bind datagram socket to given source address */ #define SKF_BIND 0x10 /* Bind datagram socket to given source address */
#define SKF_HIGH_PORT 0x20 /* Choose port from high range if possible */
#define SKF_THREAD 0x100 /* Socked used in thread, Do not add to main loop */ #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_TRUNCATED 0x200 /* Received packet was truncated, set by IO layer */

View File

@ -231,7 +231,7 @@ bfd_open_tx_sk(struct bfd_proto *p, ip_addr local, struct iface *ifa)
sk->tos = IP_PREC_INTERNET_CONTROL; sk->tos = IP_PREC_INTERNET_CONTROL;
sk->priority = sk_priority_control; sk->priority = sk_priority_control;
sk->ttl = ifa ? 255 : -1; sk->ttl = ifa ? 255 : -1;
sk->flags = SKF_THREAD | SKF_BIND; sk->flags = SKF_THREAD | SKF_BIND | SKF_HIGH_PORT;
#ifdef IPV6 #ifdef IPV6
sk->flags |= SKF_V6ONLY; sk->flags |= SKF_V6ONLY;

View File

@ -1305,7 +1305,7 @@ sk_passive_connected(sock *s, int type)
log(L_ERR "SOCK: Incoming connection: %s%#m", t->err); log(L_ERR "SOCK: Incoming connection: %s%#m", t->err);
/* FIXME: handle it better in rfree() */ /* FIXME: handle it better in rfree() */
close(t->fd); close(t->fd);
t->fd = -1; t->fd = -1;
rfree(t); rfree(t);
return 1; return 1;
@ -1348,7 +1348,7 @@ sk_open(sock *s)
bind_addr = s->saddr; bind_addr = s->saddr;
do_bind = bind_port || ipa_nonzero(bind_addr); do_bind = bind_port || ipa_nonzero(bind_addr);
break; break;
case SK_UDP: case SK_UDP:
fd = socket(af, SOCK_DGRAM, IPPROTO_UDP); fd = socket(af, SOCK_DGRAM, IPPROTO_UDP);
bind_port = s->sport; bind_port = s->sport;
@ -1399,6 +1399,14 @@ sk_open(sock *s)
} }
#endif #endif
} }
#ifdef IP_PORTRANGE
else if (s->flags & SKF_HIGH_PORT)
{
int range = IP_PORTRANGE_HIGH;
if (setsockopt(fd, IPPROTO_IP, IP_PORTRANGE, &range, sizeof(range)) < 0)
log(L_WARN "Socket error: %s%#m", "IP_PORTRANGE");
}
#endif
sockaddr_fill(&sa, af, bind_addr, s->iface, bind_port); sockaddr_fill(&sa, af, bind_addr, s->iface, bind_port);
if (bind(fd, &sa.sa, SA_LEN(sa)) < 0) if (bind(fd, &sa.sa, SA_LEN(sa)) < 0)
@ -1661,7 +1669,7 @@ sk_rx_ready(sock *s)
redo: redo:
rv = select(s->fd+1, &rd, &wr, NULL, &timo); rv = select(s->fd+1, &rd, &wr, NULL, &timo);
if ((rv < 0) && (errno == EINTR || errno == EAGAIN)) if ((rv < 0) && (errno == EINTR || errno == EAGAIN))
goto redo; goto redo;
@ -2026,5 +2034,3 @@ test_old_bird(char *path)
die("I found another BIRD running."); die("I found another BIRD running.");
close(fd); close(fd);
} }