diff options
-rw-r--r-- | bgpd/bgp_network.c | 9 | ||||
-rw-r--r-- | lib/sockunion.c | 24 | ||||
-rw-r--r-- | lib/sockunion.h | 1 | ||||
-rw-r--r-- | lib/vty.c | 1 |
4 files changed, 27 insertions, 8 deletions
diff --git a/bgpd/bgp_network.c b/bgpd/bgp_network.c index bd2e2d68..b5c4c602 100644 --- a/bgpd/bgp_network.c +++ b/bgpd/bgp_network.c @@ -387,14 +387,7 @@ bgp_listener (int sock, struct sockaddr *sa, socklen_t salen) # endif #endif -#ifdef IPV6_V6ONLY - /* Want only IPV6 on ipv6 socket (not mapped addresses) */ - if (sa->sa_family == AF_INET6) { - int on = 1; - setsockopt (sock, IPPROTO_IPV6, IPV6_V6ONLY, - (void *) &on, sizeof (on)); - } -#endif + sockopt_v6only (sa->sa_family, sock); ret = bind (sock, sa, salen); en = errno; diff --git a/lib/sockunion.c b/lib/sockunion.c index 6a40f332..d1f6d80b 100644 --- a/lib/sockunion.c +++ b/lib/sockunion.c @@ -527,6 +527,30 @@ sockopt_ttl (int family, int sock, int ttl) return 0; } +int +sockopt_v6only (int family, int sock) +{ + int ret, on = 1; + +#ifdef HAVE_IPV6 +#ifdef IPV6_V6ONLY + if (family == AF_INET6) + { + ret = setsockopt (sock, IPPROTO_IPV6, IPV6_V6ONLY, + (void *) &on, sizeof (int)); + if (ret < 0) + { + zlog (NULL, LOG_WARNING, "can't set sockopt IPV6_V6ONLY " + "to socket %d", sock); + return -1; + } + return 0; + } +#endif /* IPV6_V6ONLY */ +#endif /* HAVE_IPV6 */ + return 0; +} + /* If same family and same prefix return 1. */ int sockunion_same (union sockunion *su1, union sockunion *su2) diff --git a/lib/sockunion.h b/lib/sockunion.h index 96b9a0d4..db145cf2 100644 --- a/lib/sockunion.h +++ b/lib/sockunion.h @@ -99,6 +99,7 @@ extern int sockunion_accept (int sock, union sockunion *); extern int sockunion_stream_socket (union sockunion *); extern int sockopt_reuseaddr (int); extern int sockopt_reuseport (int); +extern int sockopt_v6only (int family, int sock); extern int sockunion_bind (int sock, union sockunion *, unsigned short, union sockunion *); extern int sockopt_ttl (int family, int sock, int ttl); @@ -1816,6 +1816,7 @@ vty_serv_sock_addrinfo (const char *hostname, unsigned short port) if (sock < 0) continue; + sockopt_v6only (ainfo->ai_family, sock); sockopt_reuseaddr (sock); sockopt_reuseport (sock); |