summaryrefslogtreecommitdiffstats
path: root/main/quagga/quagga-0.99.11-ipv6-only.patch
blob: 53636d6b57fc97dcaf112ef2185c7f1649a7270a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
On Linux the default behaviour of getaddrinfo is to provide both IPV4 and IPV6
addresses if available. But the default behaviour of binding to an IPV6 address
is to handle both the native IPV6 address and IPV4 to IPV6 mapped addresses.
Without this patch what happens is:
  1. First address is IPV6, bind succeeds.
  2. Second address is IPV4, bind fails (port already used by IPV6)
  3. incoming connections come in on IPV6 listen socket, as IPV4 mapped 
     addresses then BGP gets confused because of client with unexpected address.

The fix is to force IPV6 socket as IPV6 only.

--- a/bgpd/bgp_network.c	2008-08-27 17:59:20.000000000 -0700
+++ b/bgpd/bgp_network.c	2008-08-27 18:02:46.000000000 -0700
@@ -412,6 +412,15 @@ bgp_socket (struct bgp *bgp, unsigned sh
 	setsockopt_ipv4_tos (sock, IPTOS_PREC_INTERNETCONTROL);
 #endif
 
+#ifdef IPV6_V6ONLY
+      /* Want only IPV6 on ipv6 socket (not mapped addresses) */
+      if (ainfo->ai_family == AF_INET6) {
+	int on = 1;
+	setsockopt (sock, IPPROTO_IPV6, IPV6_V6ONLY,
+		    (void *) &on, sizeof (on));
+      }
+#endif
+
       if (bgpd_privs.change (ZPRIVS_RAISE) )
         zlog_err ("bgp_socket: could not raise privs");