mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-12-22 09:41:54 +00:00
Fixes port range socket option
This commit is contained in:
parent
ef3cac669c
commit
b867a87c2f
@ -767,6 +767,32 @@ sk_set_tos6(sock *s, int tos)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int
|
||||||
|
sk_set_high_port(sock *s)
|
||||||
|
{
|
||||||
|
/* Port range setting is optional, ignore it if not supported */
|
||||||
|
|
||||||
|
#ifdef IP_PORTRANGE
|
||||||
|
if (sk_is_ipv4(s))
|
||||||
|
{
|
||||||
|
int range = IP_PORTRANGE_HIGH;
|
||||||
|
if (setsockopt(s->fd, SOL_IP, IP_PORTRANGE, &range, sizeof(range)) < 0)
|
||||||
|
ERR("IP_PORTRANGE");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef IPV6_PORTRANGE
|
||||||
|
if (sk_is_ipv6(s))
|
||||||
|
{
|
||||||
|
int range = IPV6_PORTRANGE_HIGH;
|
||||||
|
if (setsockopt(s->fd, SOL_IPV6, IPV6_PORTRANGE, &range, sizeof(range)) < 0)
|
||||||
|
ERR("IPV6_PORTRANGE");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static inline byte *
|
static inline byte *
|
||||||
sk_skip_ip_header(byte *pkt, int *len)
|
sk_skip_ip_header(byte *pkt, int *len)
|
||||||
{
|
{
|
||||||
@ -1402,14 +1428,10 @@ sk_open(sock *s)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#ifdef IP_PORTRANGE
|
else
|
||||||
else if (s->flags & SKF_HIGH_PORT)
|
if (s->flags & SKF_HIGH_PORT)
|
||||||
{
|
if (sk_set_high_port(s) < 0)
|
||||||
int range = IP_PORTRANGE_HIGH;
|
log(L_WARN "Socket error: %s%#m", s->err);
|
||||||
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user