Mon Jan 28 20:06:52 2013 UTC ()
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


(kefren)
diff -r1.7 -r1.8 src/usr.sbin/ldpd/fsm.c
diff -r1.8 -r1.9 src/usr.sbin/ldpd/ldp_command.c
diff -r1.20 -r1.21 src/usr.sbin/ldpd/socketops.c
diff -r1.4 -r1.5 src/usr.sbin/ldpd/socketops.h

cvs diff -r1.7 -r1.8 src/usr.sbin/ldpd/fsm.c (expand / switch to unified diff)

--- src/usr.sbin/ldpd/fsm.c 2013/01/26 17:29:55 1.7
+++ src/usr.sbin/ldpd/fsm.c 2013/01/28 20:06:52 1.8
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: fsm.c,v 1.7 2013/01/26 17:29:55 kefren Exp $ */ 1/* $NetBSD: fsm.c,v 1.8 2013/01/28 20:06:52 kefren Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2010 The NetBSD Foundation, Inc. 4 * Copyright (c) 2010 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Mihai Chelaru <kefren@NetBSD.org> 8 * by Mihai Chelaru <kefren@NetBSD.org>
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -45,108 +45,113 @@ @@ -45,108 +45,113 @@
45#include "socketops.h" 45#include "socketops.h"
46#include "ldp_errors.h" 46#include "ldp_errors.h"
47#include "fsm.h" 47#include "fsm.h"
48 48
49char my_ldp_id[20]; 49char my_ldp_id[20];
50struct sockaddr mplssockaddr; 50struct sockaddr mplssockaddr;
51 51
52/* Processing a hello */ 52/* Processing a hello */
53void 53void
54run_ldp_hello(struct ldp_pdu * pduid, struct hello_tlv * ht, 54run_ldp_hello(struct ldp_pdu * pduid, struct hello_tlv * ht,
55 struct sockaddr * padd, struct in_addr * ladd, int mysock) 55 struct sockaddr * padd, struct in_addr * ladd, int mysock)
56{ 56{
57 struct ldp_peer *peer = NULL; 57 struct ldp_peer *peer = NULL;
58 union sockunion peer_addr; 
59 struct transport_address_tlv *trtlv; 58 struct transport_address_tlv *trtlv;
60 struct hello_info *hi; 59 struct hello_info *hi;
61 60
62 if ((!pduid) || (!ht)) 61 if ((!pduid) || (!ht))
63 return; 62 return;
64 63
65 debugp("Hello received for address: %s\n", inet_ntoa(*ladd)); 64 debugp("Hello received for address: %s\n", inet_ntoa(*ladd));
66 debugp("Hello: Type: 0x%.4X Length: %.2d ID: %.8X\n", ht->type, 65 debugp("Hello: Type: 0x%.4X Length: %.2d ID: %.8X\n", ht->type,
67 ht->length, ht->messageid); 66 ht->length, ht->messageid);
68 67
69 /* Add it to hello list or just update timer */ 68 /* Add it to hello list or just update timer */
70 SLIST_FOREACH(hi, &hello_info_head, infos) 69 SLIST_FOREACH(hi, &hello_info_head, infos)
71 if (hi->ldp_id.s_addr == pduid->ldp_id.s_addr) 70 if (hi->ldp_id.s_addr == pduid->ldp_id.s_addr)
72 break; 71 break;
73 if (hi == NULL) { 72 if (hi == NULL) {
74 hi = malloc(sizeof(*hi)); 73 hi = malloc(sizeof(*hi));
75 if (!hi) { 74 if (!hi) {
76 fatalp("Cannot alloc a hello info structure"); 75 fatalp("Cannot alloc a hello info structure");
77 return; 76 return;
78 } 77 }
79 hi->ldp_id.s_addr = pduid->ldp_id.s_addr; 78 hi->ldp_id.s_addr = pduid->ldp_id.s_addr;
 79 hi->transport_address.sa.sa_family = 0;
80 SLIST_INSERT_HEAD(&hello_info_head, hi, infos); 80 SLIST_INSERT_HEAD(&hello_info_head, hi, infos);
81 } else 81 } else
82 /* Just update timer */ 82 /* Just update timer */
83 hi->keepalive = LDP_HELLO_KEEP; 83 hi->keepalive = LDP_HELLO_KEEP;
84 84
85 if (ht->length <= 4) /* Common hello parameters */ 85 if (ht->length <= 4) /* Common hello parameters */
86 return; 86 return;
87 ht->ch.type = ntohs(ht->ch.type); 87 ht->ch.type = ntohs(ht->ch.type);
88 ht->ch.length = ntohs(ht->ch.length); 88 ht->ch.length = ntohs(ht->ch.length);
89 ht->ch.holdtime = ntohs(ht->ch.holdtime); 89 ht->ch.holdtime = ntohs(ht->ch.holdtime);
90 ht->ch.res = ntohs(ht->ch.res); 90 ht->ch.res = ntohs(ht->ch.res);
91 debugp("Common hello Type: 0x%.4X Length: %.2d R:%d T:%d" 91 debugp("Common hello Type: 0x%.4X Length: %.2d R:%d T:%d"
92 " Hold time: %d\n", ht->ch.type, ht->ch.length, 92 " Hold time: %d\n", ht->ch.type, ht->ch.length,
93 ht->ch.tr / 2, ht->ch.tr % 2, ht->ch.holdtime); 93 ht->ch.tr / 2, ht->ch.tr % 2, ht->ch.holdtime);
94 if (ht->ch.holdtime != 0) 94 if (ht->ch.holdtime != 0)
95 hi->keepalive = ht->ch.holdtime; 95 hi->keepalive = ht->ch.holdtime;
96 else { 96 else {
97 if (ht->ch.res >> 15 == 0) 97 if (ht->ch.res >> 15 == 0)
98 hi->keepalive = LDP_HELLO_KEEP; 98 hi->keepalive = LDP_HELLO_KEEP;
99 else 99 else
100 hi->keepalive = LDP_THELLO_KEEP; 100 hi->keepalive = LDP_THELLO_KEEP;
101 } 101 }
102 if (!get_ldp_peer_by_id(&pduid->ldp_id)) { 102 if (!get_ldp_peer_by_id(&pduid->ldp_id)) {
103 /* Check transport TLV */ 103 /* Check transport TLV */
104 if (pduid->length - PDU_PAYLOAD_LENGTH - 104 if (pduid->length - PDU_PAYLOAD_LENGTH -
105 sizeof(struct hello_tlv) > 3) { 105 sizeof(struct hello_tlv) >= 8) {
106 trtlv = (struct transport_address_tlv *) &ht[1]; 106 trtlv = (struct transport_address_tlv *)(ht + 1);
107 if (trtlv->type == TLV_IPV4_TRANSPORT) { 107 if (trtlv->type == htons(TLV_IPV4_TRANSPORT)) {
108 peer_addr.sin.sin_family = AF_INET; 108 hi->transport_address.sin.sin_family = AF_INET;
109 peer_addr.sin.sin_len = 109 hi->transport_address.sin.sin_len =
110 sizeof(struct sockaddr_in); 110 sizeof(struct sockaddr_in);
111 memcpy(&peer_addr.sin.sin_addr, &trtlv->address, 111 memcpy(&hi->transport_address.sin.sin_addr,
112 sizeof(struct in_addr)); 112 &trtlv->address, sizeof(struct in_addr));
113 } else if (trtlv->type == TLV_IPV6_TRANSPORT) { 113 } else if (trtlv->type == htons(TLV_IPV6_TRANSPORT)) {
114 peer_addr.sin6.sin6_family = AF_INET6; 114 hi->transport_address.sin6.sin6_family =
115 peer_addr.sin6.sin6_len = 115 AF_INET6;
 116 hi->transport_address.sin6.sin6_len =
116 sizeof(struct sockaddr_in6); 117 sizeof(struct sockaddr_in6);
117 memcpy(&peer_addr.sin6.sin6_addr, 118 memcpy(&hi->transport_address.sin6.sin6_addr,
118 &trtlv->address, sizeof(struct in6_addr)); 119 &trtlv->address, sizeof(struct in6_addr));
119 } 120 } else
 121 warnp("Unknown AF %x for transport address\n",
 122 ntohs(trtlv->type));
120 } else { 123 } else {
121 trtlv = NULL; 124 trtlv = NULL;
122 peer_addr.sin.sin_family = AF_INET; 125 hi->transport_address.sin.sin_family = AF_INET;
123 peer_addr.sin.sin_len = sizeof(struct sockaddr_in); 126 hi->transport_address.sin.sin_len =
124 memcpy(&peer_addr.sin.sin_addr, &pduid->ldp_id, 127 sizeof(struct sockaddr_in);
125 sizeof(struct in_addr)); 128 memcpy(&hi->transport_address.sin.sin_addr,
 129 &pduid->ldp_id, sizeof(struct in_addr));
126 } 130 }
127 /* 131 /*
128 * RFC 5036 2.5.2: If A1 > A2, LSR1 plays the active role; 132 * RFC 5036 2.5.2: If A1 > A2, LSR1 plays the active role;
129 * otherwise it is passive. 133 * otherwise it is passive.
130 */ 134 */
131 /* XXX: check for IPv6 too */ 135 /* XXX TODO: check for IPv6 too */
132 if (peer_addr.sa.sa_family == AF_INET && 136 if (hi->transport_address.sa.sa_family == AF_INET &&
133 ntohl(peer_addr.sin.sin_addr.s_addr)< ntohl(ladd->s_addr)) { 137 ntohl(hi->transport_address.sin.sin_addr.s_addr) <
 138 ntohl(ladd->s_addr)) {
134 peer = ldp_peer_new(&pduid->ldp_id, padd, 139 peer = ldp_peer_new(&pduid->ldp_id, padd,
135 trtlv != NULL ? &peer_addr.sa : NULL, 140 &hi->transport_address.sa,
136 ht->ch.holdtime, 0); 141 ht->ch.holdtime, 0);
137 if (!peer) 142 if (peer == NULL)
138 return; 143 return;
139 if (peer && peer->state == LDP_PEER_CONNECTED) 144 if (peer->state == LDP_PEER_CONNECTED)
140 send_initialize(peer); 145 send_initialize(peer);
141 } 146 }
142 } 147 }
143} 148}
144 149
145struct address_list_tlv * 150struct address_list_tlv *
146build_address_list_tlv(void) 151build_address_list_tlv(void)
147{ 152{
148 struct address_list_tlv *t; 153 struct address_list_tlv *t;
149 struct ifaddrs *ifa, *ifb; 154 struct ifaddrs *ifa, *ifb;
150 struct sockaddr_in *sa; 155 struct sockaddr_in *sa;
151 struct in_addr *ia; 156 struct in_addr *ia;
152 uint16_t adrcount = 0; 157 uint16_t adrcount = 0;

cvs diff -r1.8 -r1.9 src/usr.sbin/ldpd/ldp_command.c (expand / switch to unified diff)

--- src/usr.sbin/ldpd/ldp_command.c 2013/01/26 17:29:55 1.8
+++ src/usr.sbin/ldpd/ldp_command.c 2013/01/28 20:06:52 1.9
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ldp_command.c,v 1.8 2013/01/26 17:29:55 kefren Exp $ */ 1/* $NetBSD: ldp_command.c,v 1.9 2013/01/28 20:06:52 kefren Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2010 The NetBSD Foundation, Inc. 4 * Copyright (c) 2010 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Mihai Chelaru <kefren@NetBSD.org> 8 * by Mihai Chelaru <kefren@NetBSD.org>
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -545,28 +545,32 @@ show_debug(int s, char *recvspace) @@ -545,28 +545,32 @@ show_debug(int s, char *recvspace)
545 545
546 snprintf(sendspace, MAXSEND, "Debug: %s\n", 546 snprintf(sendspace, MAXSEND, "Debug: %s\n",
547 debug_f ? "YES" : "NO"); 547 debug_f ? "YES" : "NO");
548 writestr(s, sendspace); 548 writestr(s, sendspace);
549 return 1; 549 return 1;
550} 550}
551 551
552static int 552static int
553show_hellos(int s, char *recvspace) 553show_hellos(int s, char *recvspace)
554{ 554{
555 struct hello_info *hi; 555 struct hello_info *hi;
556 556
557 SLIST_FOREACH(hi, &hello_info_head, infos) { 557 SLIST_FOREACH(hi, &hello_info_head, infos) {
558 snprintf(sendspace, MAXSEND, "%s: %ds\n", inet_ntoa(hi->ldp_id), 558 snprintf(sendspace, MAXSEND,
559 hi->keepalive); 559 "ID: %s\nKeepalive: %ds\nTransport address: %s\n\n",
 560 inet_ntoa(hi->ldp_id),
 561 hi->keepalive,
 562 hi->transport_address.sa.sa_family != 0 ?
 563 satos(&hi->transport_address.sa) : "None");
560 writestr(s, sendspace); 564 writestr(s, sendspace);
561 } 565 }
562 return 1; 566 return 1;
563} 567}
564 568
565static int 569static int
566show_parameters(int s, char *recvspace) 570show_parameters(int s, char *recvspace)
567{ 571{
568 snprintf(sendspace, MAXSEND, "LDP ID: %s\nProtocol version: %d\n" 572 snprintf(sendspace, MAXSEND, "LDP ID: %s\nProtocol version: %d\n"
569 "Hello time: %d\nKeepalive time: %d\nHoldtime: %d\n" 573 "Hello time: %d\nKeepalive time: %d\nHoldtime: %d\n"
570 "Minimum label: %d\nMaximum label: %d\n", 574 "Minimum label: %d\nMaximum label: %d\n",
571 my_ldp_id, 575 my_ldp_id,
572 LDP_VERSION, 576 LDP_VERSION,

cvs diff -r1.20 -r1.21 src/usr.sbin/ldpd/socketops.c (expand / switch to unified diff)

--- src/usr.sbin/ldpd/socketops.c 2013/01/26 21:07:49 1.20
+++ src/usr.sbin/ldpd/socketops.c 2013/01/28 20:06:52 1.21
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: socketops.c,v 1.20 2013/01/26 21:07:49 kefren Exp $ */ 1/* $NetBSD: socketops.c,v 1.21 2013/01/28 20:06:52 kefren Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2010 The NetBSD Foundation, Inc. 4 * Copyright (c) 2010 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Mihai Chelaru <kefren@NetBSD.org> 8 * by Mihai Chelaru <kefren@NetBSD.org>
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -741,35 +741,33 @@ send_hello_alarm(int unused) @@ -741,35 +741,33 @@ send_hello_alarm(int unused)
741 break; 741 break;
742 } /* switch */ 742 } /* switch */
743 743
744 /* send keepalives */ 744 /* send keepalives */
745 if (!(t % ldp_keepalive_time)) { 745 if (!(t % ldp_keepalive_time)) {
746 SLIST_FOREACH(p, &ldp_peer_head, peers)  746 SLIST_FOREACH(p, &ldp_peer_head, peers)
747 if (p->state == LDP_PEER_ESTABLISHED) { 747 if (p->state == LDP_PEER_ESTABLISHED) {
748 debugp("Sending KeepAlive to %s\n", 748 debugp("Sending KeepAlive to %s\n",
749 inet_ntoa(p->ldp_id)); 749 inet_ntoa(p->ldp_id));
750 keep_alive(p); 750 keep_alive(p);
751 } 751 }
752 } 752 }
753 753
754 /* Decrement hello info keepalives */ 754 /* Decrement and Check hello keepalives */
755 SLIST_FOREACH(hi, &hello_info_head, infos) 755 SLIST_FOREACH_SAFE(hi, &hello_info_head, infos, hinext) {
756 if (hi->keepalive != 0xFFFF) 756 if (hi->keepalive != 0xFFFF)
757 hi->keepalive--; 757 hi->keepalive--;
758 
759 /* Check hello keepalives */ 
760 SLIST_FOREACH_SAFE(hi, &hello_info_head, infos, hinext) 
761 if (hi->keepalive < 1) 758 if (hi->keepalive < 1)
762 SLIST_REMOVE(&hello_info_head, hi, hello_info, infos); 759 SLIST_REMOVE(&hello_info_head, hi, hello_info, infos);
 760 }
763 761
764 /* Set the alarm again and bail out */ 762 /* Set the alarm again and bail out */
765 alarm(1); 763 alarm(1);
766 errno = olderrno; 764 errno = olderrno;
767} 765}
768 766
769static void  767static void
770bail_out(int x) 768bail_out(int x)
771{ 769{
772 ldp_peer_holddown_all(); 770 ldp_peer_holddown_all();
773 flush_mpls_routes(); 771 flush_mpls_routes();
774 exit(0); 772 exit(0);
775} 773}

cvs diff -r1.4 -r1.5 src/usr.sbin/ldpd/socketops.h (expand / switch to unified diff)

--- src/usr.sbin/ldpd/socketops.h 2013/01/26 17:29:55 1.4
+++ src/usr.sbin/ldpd/socketops.h 2013/01/28 20:06:52 1.5
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: socketops.h,v 1.4 2013/01/26 17:29:55 kefren Exp $ */ 1/* $NetBSD: socketops.h,v 1.5 2013/01/28 20:06:52 kefren Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2010 The NetBSD Foundation, Inc. 4 * Copyright (c) 2010 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Mihai Chelaru <kefren@NetBSD.org> 8 * by Mihai Chelaru <kefren@NetBSD.org>
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -46,26 +46,27 @@ int create_hello_sockets(void); @@ -46,26 +46,27 @@ int create_hello_sockets(void);
46int create_listening_socket(void); 46int create_listening_socket(void);
47void send_hello(void); 47void send_hello(void);
48int get_message_id(void); 48int get_message_id(void);
49int the_big_loop(void); 49int the_big_loop(void);
50void new_peer_connection(void); 50void new_peer_connection(void);
51void send_initialize(struct ldp_peer *); 51void send_initialize(struct ldp_peer *);
52void keep_alive(struct ldp_peer *); 52void keep_alive(struct ldp_peer *);
53void recv_session_pdu(struct ldp_peer *); 53void recv_session_pdu(struct ldp_peer *);
54int send_message(struct ldp_peer *, struct ldp_pdu *, struct tlv *); 54int send_message(struct ldp_peer *, struct ldp_pdu *, struct tlv *);
55int send_tlv(struct ldp_peer *, struct tlv *); 55int send_tlv(struct ldp_peer *, struct tlv *);
56int send_addresses(struct ldp_peer *); 56int send_addresses(struct ldp_peer *);
57 57
58struct hello_info { 58struct hello_info {
59 struct in_addr address, transport_address, ldp_id; 59 union sockunion transport_address;
 60 struct in_addr ldp_id;
60 int keepalive; 61 int keepalive;
61 SLIST_ENTRY(hello_info) infos; 62 SLIST_ENTRY(hello_info) infos;
62}; 63};
63SLIST_HEAD(,hello_info) hello_info_head; 64SLIST_HEAD(,hello_info) hello_info_head;
64 65
65struct hello_socket { 66struct hello_socket {
66 int type, socket; 67 int type, socket;
67 SLIST_ENTRY(hello_socket) listentry; 68 SLIST_ENTRY(hello_socket) listentry;
68}; 69};
69SLIST_HEAD(,hello_socket) hello_socket_head; 70SLIST_HEAD(,hello_socket) hello_socket_head;
70 71
71#endif /* !_SOCKETOPS_H_ */ 72#endif /* !_SOCKETOPS_H_ */