philipp / rpms / dhcp

Forked from rpms/dhcp 4 years ago
Clone

Blame SOURCES/dhcp-hop-limit.patch

c360e8
From accb28721d061f2e06e927bdb1337317db3aa706 Mon Sep 17 00:00:00 2001
c360e8
From: Thomas Markwalder <tmark@isc.org>
c360e8
Date: Mon, 19 Jan 2015 13:40:25 -0500
c360e8
Subject: [PATCH] [v4_2] Fixed inconsistencies in setting hop count limit in
c360e8
 dhcrelay
c360e8
c360e8
diff --git a/common/socket.c b/common/socket.c
c360e8
index c170448..5467a35 100644
c360e8
--- a/common/socket.c
c360e8
+++ b/common/socket.c
c360e8
@@ -300,18 +300,24 @@ if_register_socket(struct interface_info *info, int family,
c360e8
 #endif
c360e8
 	}
c360e8
 
c360e8
-	if ((family == AF_INET6) &&
c360e8
-	    ((info->flags & INTERFACE_UPSTREAM) != 0)) {
c360e8
-		int hop_limit = 32;
c360e8
-		if (setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
c360e8
-			       &hop_limit, sizeof(int)) < 0) {
c360e8
-			log_fatal("setsockopt: IPV6_MULTICAST_HOPS: %m");
c360e8
-		}
c360e8
-	}
c360e8
 #endif /* DHCPv6 */
c360e8
 
c360e8
 	return sock;
c360e8
 }
c360e8
+
c360e8
+#ifdef DHCPv6
c360e8
+void set_multicast_hop_limit(struct interface_info* info, int hop_limit) {
c360e8
+	if (setsockopt(info->wfdesc, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
c360e8
+		       &hop_limit, sizeof(int)) < 0) {
c360e8
+		log_fatal("setMulticaseHopLimit: IPV6_MULTICAST_HOPS: %m");
c360e8
+	}
c360e8
+
c360e8
+	log_debug("Setting hop count limit to %d for interface %s",
c360e8
+		  hop_limit, info->name);
c360e8
+
c360e8
+}
c360e8
+#endif /* DHCPv6 */
c360e8
+
c360e8
 #endif /* USE_SOCKET_SEND || USE_SOCKET_RECEIVE || USE_SOCKET_FALLBACK */
c360e8
 
c360e8
 #if defined (USE_SOCKET_SEND) || defined (USE_SOCKET_FALLBACK)
c360e8
diff --git a/includes/dhcpd.h b/includes/dhcpd.h
c360e8
index 2b15430..bd11b48 100644
c360e8
--- a/includes/dhcpd.h
c360e8
+++ b/includes/dhcpd.h
c360e8
@@ -2386,6 +2386,8 @@ void get_hw_addr(const char *name, struct hardware *hw);
c360e8
 #if defined (USE_SOCKET_SEND) || defined (USE_SOCKET_RECEIVE) \
c360e8
 	|| defined (USE_SOCKET_FALLBACK)
c360e8
 int if_register_socket(struct interface_info *, int, int *, struct in6_addr *);
c360e8
+
c360e8
+void set_multicast_hop_limit(struct interface_info* info, int hop_limit);
c360e8
 #endif
c360e8
 
c360e8
 #if defined (USE_SOCKET_FALLBACK) && !defined (USE_SOCKET_SEND)
c360e8
diff --git a/relay/dhcrelay.c b/relay/dhcrelay.c
c360e8
index 927e404..ad76d3e 100644
c360e8
--- a/relay/dhcrelay.c
c360e8
+++ b/relay/dhcrelay.c
c360e8
@@ -1173,8 +1173,8 @@ parse_downstream(char *arg) {
c360e8
 	/* Share with up side? */
c360e8
 	for (up = upstreams; up; up = up->next) {
c360e8
 		if (strcmp(ifname, up->ifp->name) == 0) {
c360e8
-			log_info("Interface '%s' is both down and up.",
c360e8
-				 ifname);
c360e8
+			log_info("parse_downstream: Interface '%s' is "
c360e8
+				 "both down and up.", ifname);
c360e8
 			ifp = up->ifp;
c360e8
 			break;
c360e8
 		}
c360e8
@@ -1192,8 +1192,8 @@ parse_downstream(char *arg) {
c360e8
 			interface_dereference(&interfaces, MDL);
c360e8
 		}
c360e8
 		interface_reference(&interfaces, ifp, MDL);
c360e8
-		ifp->flags |= INTERFACE_REQUESTED | INTERFACE_DOWNSTREAM;
c360e8
 	}
c360e8
+	ifp->flags |= INTERFACE_REQUESTED | INTERFACE_DOWNSTREAM;
c360e8
 
c360e8
 	/* New downstream. */
c360e8
 	dp = (struct stream_list *) dmalloc(sizeof(*dp), MDL);
c360e8
@@ -1244,6 +1244,8 @@ parse_upstream(char *arg) {
c360e8
 	}
c360e8
 	for (dp = downstreams; dp; dp = dp->next) {
c360e8
 		if (strcmp(ifname, dp->ifp->name) == 0) {
c360e8
+			log_info("parse_upstream: Interface '%s' is "
c360e8
+				 "both down and up.", ifname);
c360e8
 			ifp = dp->ifp;
c360e8
 			break;
c360e8
 		}
c360e8
@@ -1261,8 +1263,8 @@ parse_upstream(char *arg) {
c360e8
 			interface_dereference(&interfaces, MDL);
c360e8
 		}
c360e8
 		interface_reference(&interfaces, ifp, MDL);
c360e8
-		ifp->flags |= INTERFACE_REQUESTED | INTERFACE_UPSTREAM;
c360e8
 	}
c360e8
+	ifp->flags |= INTERFACE_REQUESTED | INTERFACE_UPSTREAM;
c360e8
 
c360e8
 	/* New upstream. */
c360e8
 	up = (struct stream_list *) dmalloc(sizeof(*up), MDL);
c360e8
@@ -1330,6 +1332,13 @@ setup_streams(void) {
c360e8
 		if (up->ifp->v6address_count == 0)
c360e8
 			log_fatal("Interface '%s' has no IPv6 addresses.",
c360e8
 				  up->ifp->name);
c360e8
+
c360e8
+		/* RFC 3315 Sec 20 - "If the relay agent relays messages to
c360e8
+		 * the All_DHCP_Servers address or other multicast addresses,
c360e8
+		 * it sets the Hop Limit field to 32." */
c360e8
+		if (IN6_IS_ADDR_MULTICAST(&up->link.sin6_addr)) {
c360e8
+			set_multicast_hop_limit(up->ifp, HOP_COUNT_LIMIT);
c360e8
+		}
c360e8
 	}
c360e8
 }
c360e8
 
c360e8
-- 
c360e8
2.1.0
c360e8