[PATCH 6/6] dhcrelay: Add D6O_SUBSCRIBER_ID to DHCPv6 relayed packets

Bjørn Mork bjorn at mork.no
Sun Sep 25 12:59:49 UTC 2011


Adding D6O_SUBSCRIBER_ID as specified by RFC4580

The circuit_id field of interface_info is unused since the DHCPv6
relaying code has its own integer field for handling D6O_INTERFACE_ID
We reuse this for storing the subscriber id.

Signed-off-by: Bjørn Mork <bjorn at mork.no>
---
 relay/dhcrelay.8 |    5 +++--
 relay/dhcrelay.c |   24 +++++++++++++++++++++---
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/relay/dhcrelay.8 b/relay/dhcrelay.8
index c4115cb..1a0e90f 100644
--- a/relay/dhcrelay.8
+++ b/relay/dhcrelay.8
@@ -238,7 +238,7 @@ be silently ignored.
 Specifies the IANA allocated enterprise number to be used in REMOTE-ID
 options.  Required for adding REMOTE-ID
 .TP
--l [\fIaddress%\fR]\fIifname\fR[\fI#index\fR][\fI!remoteid\fR]
+-l [\fIaddress%\fR]\fIifname\fR[\fI#index\fR][\fI!remoteid\fR][\fI&subscriberid\fR]
 Specifies the ``lower'' network interface for DHCPv6 relay mode: the
 interface on which queries will be received from clients or from other
 relay agents.  At least one \fB-l\fR option must be included in the command
@@ -248,7 +248,8 @@ if it isn't, dhcrelay will use the first non-link-local address configured
 on the interface unless configured for LDRA with the \fB-L\fR option.
 The optional \fI#index\fR parameter specifies the interface index. The
 optional \fI!remoteid\fR parameter specifies the ascii remote id value
-(requires the \fB-e\fR option as well).
+(requires the \fB-e\fR option as well). The optional \fI&subscriberid\fR
+parameter enables adding a subscriber-id option.
 .TP
 -u [\fIaddress%\fR]\fIifname\fR
 Specifies the ``upper'' network interface for DHCPv6 relay mode: the
diff --git a/relay/dhcrelay.c b/relay/dhcrelay.c
index f00aa2f..b37dc9e 100644
--- a/relay/dhcrelay.c
+++ b/relay/dhcrelay.c
@@ -156,7 +156,7 @@ static const char url[] =
 "                     -e <enterprisenumber>\n"\
 "                     -l lower0 [ ... -l lowerN]\n" \
 "                     -u upper0 [ ... -u upperN]\n" \
-"       lower (client link): [address%%]interface[#index][!remoteid]\n" \
+"       lower (client link): [address%%]interface[#index][!remoteid][&subscriberid]\n" \
 "       upper (server link): [address%%]interface"
 #else
 #define DHCRELAY_USAGE \
@@ -1147,13 +1147,13 @@ add_relay_agent_options(struct interface_info *ip, struct dhcp_packet *packet,
 
 #ifdef DHCPv6
 /*
- * Parse a downstream argument: [address%]interface[#index][!remoteid].
+ * Parse a downstream argument: [address%]interface[#index][!remoteid][&subscriberid].
  */
 static struct stream_list *
 parse_downstream(char *arg) {
 	struct stream_list *dp, *up;
 	struct interface_info *ifp = NULL;
-	char *ifname, *addr, *iid, *rid;
+	char *ifname, *addr, *iid, *rid, *sid;
 	isc_result_t status;
 
 	if (!supports_multiple_interfaces(ifp) &&
@@ -1169,6 +1169,10 @@ parse_downstream(char *arg) {
 		*ifname++ = '\0';
 		addr = arg;
 	}
+	sid = strchr(ifname, '&');
+	if (sid != NULL) {
+		*sid++ = '\0';
+	}
 	rid = strchr(ifname, '!');
 	if (rid != NULL) {
 		*rid++ = '\0';
@@ -1231,6 +1235,11 @@ parse_downstream(char *arg) {
 		dp->ifp->remote_id = (u_int8_t *) remote_id;
 		dp->ifp->remote_id_len = sizeof(int) + strlen(rid);
 	}
+	/* we're overloading the circuit_id option */
+	if (sid != NULL) {
+		ifp->circuit_id = (u_int8_t *) sid;
+		ifp->circuit_id_len = strlen(sid);
+	}
 	/* !addr case handled by setup. */
 	if (!rfc6221_ldra && /* silently ignore any addr for LDRA */
 		addr && (inet_pton(AF_INET6, addr, &dp->link.sin6_addr) <= 0))
@@ -1370,6 +1379,7 @@ setup_streams(void) {
 static const int required_forw_opts[] = {
 	D6O_INTERFACE_ID,
 	D6O_REMOTE_ID,
+	D6O_SUBSCRIBER_ID,
 	D6O_RELAY_MSG,
 	0
 };
@@ -1481,6 +1491,14 @@ opt_error:
 					D6O_REMOTE_ID, 0))
 		goto opt_error;
 
+	/* add subscriber id */
+	if (dp->ifp->circuit_id &&
+		!save_option_buffer(&dhcpv6_universe, opts,
+					NULL, dp->ifp->circuit_id,
+					dp->ifp->circuit_id_len,
+					D6O_SUBSCRIBER_ID, 0))
+		goto opt_error;
+
 	/* Add the relay-msg carrying the packet. */
 	if (!save_option_buffer(&dhcpv6_universe, opts,
 				NULL, (unsigned char *) packet->raw,
-- 
1.7.2.5




More information about the dhcp-users mailing list