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

@ -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)
@ -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);
} }