Module Name:    src
Committed By:   kefren
Date:           Mon Jan 28 20:06:52 UTC 2013

Modified Files:
        src/usr.sbin/ldpd: fsm.c ldp_command.c socketops.c socketops.h

Log Message:
Fix the transport address TLV mess I created after INET6 convert
Use a single loop to decrement and check hello list keepalives
Display transport address in show hello output


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/ldpd/fsm.c
cvs rdiff -u -r1.8 -r1.9 src/usr.sbin/ldpd/ldp_command.c
cvs rdiff -u -r1.20 -r1.21 src/usr.sbin/ldpd/socketops.c
cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/ldpd/socketops.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/ldpd/fsm.c
diff -u src/usr.sbin/ldpd/fsm.c:1.7 src/usr.sbin/ldpd/fsm.c:1.8
--- src/usr.sbin/ldpd/fsm.c:1.7	Sat Jan 26 17:29:55 2013
+++ src/usr.sbin/ldpd/fsm.c	Mon Jan 28 20:06:52 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: fsm.c,v 1.7 2013/01/26 17:29:55 kefren Exp $ */
+/* $NetBSD: fsm.c,v 1.8 2013/01/28 20:06:52 kefren Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -55,7 +55,6 @@ run_ldp_hello(struct ldp_pdu * pduid, st
     struct sockaddr * padd, struct in_addr * ladd, int mysock)
 {
 	struct ldp_peer *peer = NULL;
-	union sockunion peer_addr;
 	struct transport_address_tlv *trtlv;
 	struct hello_info *hi;
 
@@ -77,6 +76,7 @@ run_ldp_hello(struct ldp_pdu * pduid, st
 			return;
 		}
 		hi->ldp_id.s_addr = pduid->ldp_id.s_addr;
+		hi->transport_address.sa.sa_family = 0;
 		SLIST_INSERT_HEAD(&hello_info_head, hi, infos);
 	} else
 		/* Just update timer */
@@ -102,41 +102,46 @@ run_ldp_hello(struct ldp_pdu * pduid, st
 	if (!get_ldp_peer_by_id(&pduid->ldp_id)) {
 		/* Check transport TLV */
 		if (pduid->length - PDU_PAYLOAD_LENGTH -
-		    sizeof(struct hello_tlv) > 3) {
-			trtlv = (struct transport_address_tlv *) &ht[1];
-			if (trtlv->type == TLV_IPV4_TRANSPORT) {
-				peer_addr.sin.sin_family = AF_INET;
-				peer_addr.sin.sin_len =
+		    sizeof(struct hello_tlv) >= 8) {
+			trtlv = (struct transport_address_tlv *)(ht + 1);
+			if (trtlv->type == htons(TLV_IPV4_TRANSPORT)) {
+				hi->transport_address.sin.sin_family = AF_INET;
+				hi->transport_address.sin.sin_len =
 				    sizeof(struct sockaddr_in);
-				memcpy(&peer_addr.sin.sin_addr, &trtlv->address,
-				    sizeof(struct in_addr));
-			} else if (trtlv->type == TLV_IPV6_TRANSPORT) {
-				peer_addr.sin6.sin6_family = AF_INET6;
-				peer_addr.sin6.sin6_len =
+				memcpy(&hi->transport_address.sin.sin_addr,
+				    &trtlv->address, sizeof(struct in_addr));
+			} else if (trtlv->type == htons(TLV_IPV6_TRANSPORT)) {
+				hi->transport_address.sin6.sin6_family =
+				    AF_INET6;
+				hi->transport_address.sin6.sin6_len =
 				    sizeof(struct sockaddr_in6);
-				memcpy(&peer_addr.sin6.sin6_addr,
+				memcpy(&hi->transport_address.sin6.sin6_addr,
 				    &trtlv->address, sizeof(struct in6_addr));
-			}
+			} else
+				warnp("Unknown AF %x for transport address\n",
+				    ntohs(trtlv->type));
 		} else {
 			trtlv = NULL;
-			peer_addr.sin.sin_family = AF_INET;
-			peer_addr.sin.sin_len = sizeof(struct sockaddr_in);
-			memcpy(&peer_addr.sin.sin_addr, &pduid->ldp_id,
-			    sizeof(struct in_addr));
+			hi->transport_address.sin.sin_family = AF_INET;
+			hi->transport_address.sin.sin_len =
+			    sizeof(struct sockaddr_in);
+			memcpy(&hi->transport_address.sin.sin_addr,
+			    &pduid->ldp_id, sizeof(struct in_addr));
 		}
 		/*
 		 * RFC 5036 2.5.2: If A1 > A2, LSR1 plays the active role;
 		 * otherwise it is passive.
 		 */
-		/* XXX: check for IPv6 too */
-		if (peer_addr.sa.sa_family == AF_INET &&
-		    ntohl(peer_addr.sin.sin_addr.s_addr)< ntohl(ladd->s_addr)) {
+		/* XXX TODO: check for IPv6 too */
+		if (hi->transport_address.sa.sa_family == AF_INET &&
+		    ntohl(hi->transport_address.sin.sin_addr.s_addr) <
+		    ntohl(ladd->s_addr)) {
 			peer = ldp_peer_new(&pduid->ldp_id, padd,
-				trtlv != NULL ? &peer_addr.sa : NULL,
+				&hi->transport_address.sa,
 				ht->ch.holdtime, 0);
-			if (!peer)
+			if (peer == NULL)
 				return;
-			if (peer && peer->state == LDP_PEER_CONNECTED)
+			if (peer->state == LDP_PEER_CONNECTED)
 				send_initialize(peer);
 		}
 	}

Index: src/usr.sbin/ldpd/ldp_command.c
diff -u src/usr.sbin/ldpd/ldp_command.c:1.8 src/usr.sbin/ldpd/ldp_command.c:1.9
--- src/usr.sbin/ldpd/ldp_command.c:1.8	Sat Jan 26 17:29:55 2013
+++ src/usr.sbin/ldpd/ldp_command.c	Mon Jan 28 20:06:52 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: ldp_command.c,v 1.8 2013/01/26 17:29:55 kefren Exp $ */
+/* $NetBSD: ldp_command.c,v 1.9 2013/01/28 20:06:52 kefren Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -555,8 +555,12 @@ show_hellos(int s, char *recvspace)
 	struct hello_info *hi;
 
 	SLIST_FOREACH(hi, &hello_info_head, infos) {
-		snprintf(sendspace, MAXSEND, "%s: %ds\n", inet_ntoa(hi->ldp_id),
-		    hi->keepalive);
+		snprintf(sendspace, MAXSEND,
+		    "ID: %s\nKeepalive: %ds\nTransport address: %s\n\n",
+		    inet_ntoa(hi->ldp_id),
+		    hi->keepalive,
+		    hi->transport_address.sa.sa_family != 0 ?
+		    satos(&hi->transport_address.sa) : "None");
 		writestr(s, sendspace);
 	}
 	return 1;

Index: src/usr.sbin/ldpd/socketops.c
diff -u src/usr.sbin/ldpd/socketops.c:1.20 src/usr.sbin/ldpd/socketops.c:1.21
--- src/usr.sbin/ldpd/socketops.c:1.20	Sat Jan 26 21:07:49 2013
+++ src/usr.sbin/ldpd/socketops.c	Mon Jan 28 20:06:52 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: socketops.c,v 1.20 2013/01/26 21:07:49 kefren Exp $ */
+/* $NetBSD: socketops.c,v 1.21 2013/01/28 20:06:52 kefren Exp $ */
 
 /*
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -751,15 +751,13 @@ send_hello_alarm(int unused)
 		    }
 	}
 
-	/* Decrement hello info keepalives */
-	SLIST_FOREACH(hi, &hello_info_head, infos)
+	/* Decrement and Check hello keepalives */
+	SLIST_FOREACH_SAFE(hi, &hello_info_head, infos, hinext) {
 		if (hi->keepalive != 0xFFFF)
 			hi->keepalive--;
-
-	/* Check hello keepalives */
-	SLIST_FOREACH_SAFE(hi, &hello_info_head, infos, hinext)
 		if (hi->keepalive < 1)
 			SLIST_REMOVE(&hello_info_head, hi, hello_info, infos);
+	}
 
 	/* Set the alarm again and bail out */
 	alarm(1);

Index: src/usr.sbin/ldpd/socketops.h
diff -u src/usr.sbin/ldpd/socketops.h:1.4 src/usr.sbin/ldpd/socketops.h:1.5
--- src/usr.sbin/ldpd/socketops.h:1.4	Sat Jan 26 17:29:55 2013
+++ src/usr.sbin/ldpd/socketops.h	Mon Jan 28 20:06:52 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: socketops.h,v 1.4 2013/01/26 17:29:55 kefren Exp $ */
+/* $NetBSD: socketops.h,v 1.5 2013/01/28 20:06:52 kefren Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -56,7 +56,8 @@ int	send_tlv(struct ldp_peer *, struct t
 int	send_addresses(struct ldp_peer *);
 
 struct	hello_info {
-	struct in_addr address, transport_address, ldp_id;
+	union sockunion transport_address;
+	struct in_addr ldp_id;
 	int keepalive;
 	SLIST_ENTRY(hello_info) infos;
 };

Reply via email to