philipp / rpms / dhcp

Forked from rpms/dhcp 4 years ago
Clone

Blame SOURCES/dhcp-hop-limit.patch

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