CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: joerg Date: Tue Feb 23 15:05:09 UTC 2021 Modified Files: src/usr.sbin/ldpd: Makefile Log Message: Make use of packed member addreses non-fatal for clang, too To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/ldpd/Makefile 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/Makefile diff -u src/usr.sbin/ldpd/Makefile:1.6 src/usr.sbin/ldpd/Makefile:1.7 --- src/usr.sbin/ldpd/Makefile:1.6 Wed Feb 3 06:46:27 2021 +++ src/usr.sbin/ldpd/Makefile Tue Feb 23 15:05:08 2021 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.6 2021/02/03 06:46:27 roy Exp $ +# $NetBSD: Makefile,v 1.7 2021/02/23 15:05:08 joerg Exp $ .include @@ -26,6 +26,7 @@ LDADD+= -lcrypt CPPFLAGS+=-DINET6 .endif +CWARNFLAGS.clang+= -Wno-error=address-of-packed-member CWARNFLAGS.gcc+=${GCC_NO_ADDR_OF_PACKED_MEMBER} .include
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: roy Date: Wed Feb 3 06:46:27 UTC 2021 Modified Files: src/usr.sbin/ldpd: Makefile Log Message: ldpd: Discard warning about accessing packed member I don't see a good way of fixing this right now. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/ldpd/Makefile 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/Makefile diff -u src/usr.sbin/ldpd/Makefile:1.5 src/usr.sbin/ldpd/Makefile:1.6 --- src/usr.sbin/ldpd/Makefile:1.5 Fri Oct 18 10:49:19 2013 +++ src/usr.sbin/ldpd/Makefile Wed Feb 3 06:46:27 2021 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.5 2013/10/18 10:49:19 kefren Exp $ +# $NetBSD: Makefile,v 1.6 2021/02/03 06:46:27 roy Exp $ .include @@ -26,4 +26,6 @@ LDADD+= -lcrypt CPPFLAGS+=-DINET6 .endif +CWARNFLAGS.gcc+=${GCC_NO_ADDR_OF_PACKED_MEMBER} + .include
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: joerg Date: Wed Apr 22 23:53:27 UTC 2020 Modified Files: src/usr.sbin/ldpd: conffile.c conffile.h ldp_peer.c ldp_peer.h socketops.c socketops.h Log Message: Avoid common symbol definitions To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/usr.sbin/ldpd/conffile.c cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/ldpd/conffile.h cvs rdiff -u -r1.16 -r1.17 src/usr.sbin/ldpd/ldp_peer.c cvs rdiff -u -r1.8 -r1.9 src/usr.sbin/ldpd/ldp_peer.h cvs rdiff -u -r1.34 -r1.35 src/usr.sbin/ldpd/socketops.c cvs rdiff -u -r1.6 -r1.7 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/conffile.c diff -u src/usr.sbin/ldpd/conffile.c:1.12 src/usr.sbin/ldpd/conffile.c:1.13 --- src/usr.sbin/ldpd/conffile.c:1.12 Tue Jan 10 21:02:38 2017 +++ src/usr.sbin/ldpd/conffile.c Wed Apr 22 23:53:27 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: conffile.c,v 1.12 2017/01/10 21:02:38 christos Exp $ */ +/* $NetBSD: conffile.c,v 1.13 2020/04/22 23:53:27 joerg Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -47,6 +47,9 @@ #define NextCommand(x) strsep(, " ") #define LINEMAXSIZE 1024 +struct coifs_head coifs_head; +struct conei_head conei_head; + char *mapped, *nextline; size_t mapsize; Index: src/usr.sbin/ldpd/conffile.h diff -u src/usr.sbin/ldpd/conffile.h:1.4 src/usr.sbin/ldpd/conffile.h:1.5 --- src/usr.sbin/ldpd/conffile.h:1.4 Thu Oct 17 18:10:23 2013 +++ src/usr.sbin/ldpd/conffile.h Wed Apr 22 23:53:27 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: conffile.h,v 1.4 2013/10/17 18:10:23 kefren Exp $ */ +/* $NetBSD: conffile.h,v 1.5 2020/04/22 23:53:27 joerg Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -49,7 +49,7 @@ struct conf_neighbour { int authenticate; /* RFC 2385 */ SLIST_ENTRY(conf_neighbour) neilist; }; -SLIST_HEAD(,conf_neighbour) conei_head; +extern SLIST_HEAD(conei_head,conf_neighbour) conei_head; struct conf_interface { char if_name[IF_NAMESIZE]; @@ -57,7 +57,7 @@ struct conf_interface { int passive; SLIST_ENTRY(conf_interface) iflist; }; -SLIST_HEAD(,conf_interface) coifs_head; +extern SLIST_HEAD(coifs_head,conf_interface) coifs_head; int conf_parsefile(const char *fname); Index: src/usr.sbin/ldpd/ldp_peer.c diff -u src/usr.sbin/ldpd/ldp_peer.c:1.16 src/usr.sbin/ldpd/ldp_peer.c:1.17 --- src/usr.sbin/ldpd/ldp_peer.c:1.16 Fri Aug 2 07:29:56 2013 +++ src/usr.sbin/ldpd/ldp_peer.c Wed Apr 22 23:53:27 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: ldp_peer.c,v 1.16 2013/08/02 07:29:56 kefren Exp $ */ +/* $NetBSD: ldp_peer.c,v 1.17 2020/04/22 23:53:27 joerg Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -55,6 +55,7 @@ #include "ldp_peer.h" extern int ldp_holddown_time; +struct ldp_peer_head ldp_peer_head; static struct label_mapping *ldp_peer_get_lm(struct ldp_peer *, const struct sockaddr *, uint); Index: src/usr.sbin/ldpd/ldp_peer.h diff -u src/usr.sbin/ldpd/ldp_peer.h:1.8 src/usr.sbin/ldpd/ldp_peer.h:1.9 --- src/usr.sbin/ldpd/ldp_peer.h:1.8 Fri Aug 2 07:29:56 2013 +++ src/usr.sbin/ldpd/ldp_peer.h Wed Apr 22 23:53:27 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: ldp_peer.h,v 1.8 2013/08/02 07:29:56 kefren Exp $ */ +/* $NetBSD: ldp_peer.h,v 1.9 2020/04/22 23:53:27 joerg Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -74,7 +74,7 @@ struct ldp_peer { SLIST_ENTRY(ldp_peer) peers; }; -SLIST_HEAD(,ldp_peer) ldp_peer_head; +extern SLIST_HEAD(ldp_peer_head,ldp_peer) ldp_peer_head; struct peer_map { struct ldp_peer *peer; Index: src/usr.sbin/ldpd/socketops.c diff -u src/usr.sbin/ldpd/socketops.c:1.34 src/usr.sbin/ldpd/socketops.c:1.35 --- src/usr.sbin/ldpd/socketops.c:1.34 Wed Apr 12 17:02:51 2017 +++ src/usr.sbin/ldpd/socketops.c Wed Apr 22 23:53:27 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: socketops.c,v 1.34 2017/04/12 17:02:51 roy Exp $ */ +/* $NetBSD: socketops.c,v 1.35 2020/04/22 23:53:27 joerg Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -61,6 +61,9 @@ #include "ldp_errors.h" #include "socketops.h" +struct hello_info_head hello_info_head; +static SLIST_HEAD(,hello_socket) hello_socket_head; + int ls;/* TCP listening socket on port 646 */ int route_socket; /* used to see when a route is added/deleted */ int command_socket; /* Listening socket for interface command */ Index: src/usr.sbin/ldpd/socketops.h diff -u src/usr.sbin/ldpd/socketops.h:1.6 src/usr.sbin/ldpd/socketops.h:1.7 --- src/usr.sbin/ldpd/socketops.h:1.6 Thu Jul 11 05:45:23 2013 +++ src/usr.sbin/ldpd/socketops.h Wed Apr 22 23:53:27 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: socketops.h,v 1.6 2013/07/11 05:45:23 kefren Exp $ */ +/* $NetBSD: socketops.h,v 1.7 2020/04/22 23:53:27 joerg Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -62,12 +62,11 @@ struct hello_info { int keepalive; SLIST_ENTRY(hello_info) infos; };
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: roy Date: Wed Apr 12 17:02:51 UTC 2017 Modified Files: src/usr.sbin/ldpd: socketops.c Log Message: Use RO_MSGFILTER. To generate a diff of this commit: cvs rdiff -u -r1.33 -r1.34 src/usr.sbin/ldpd/socketops.c 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/socketops.c diff -u src/usr.sbin/ldpd/socketops.c:1.33 src/usr.sbin/ldpd/socketops.c:1.34 --- src/usr.sbin/ldpd/socketops.c:1.33 Wed Oct 30 08:41:57 2013 +++ src/usr.sbin/ldpd/socketops.c Wed Apr 12 17:02:51 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: socketops.c,v 1.33 2013/10/30 08:41:57 mrg Exp $ */ +/* $NetBSD: socketops.c,v 1.34 2017/04/12 17:02:51 roy Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -817,6 +817,12 @@ the_big_loop(void) struct pollfd pfd[MAX_POLL_FDS]; struct hello_socket *hs; nfds_t pollsum; +#ifdef RO_MSGFILTER + unsigned char msgfilter[] = { + RTM_NEWADDR, RTM_DELADDR, + RTM_ADD, RTM_DELETE, RTM_CHANGE, + }; +#endif assert(MAX_POLL_FDS > 5); @@ -835,6 +841,10 @@ the_big_loop(void) route_socket = socket(PF_ROUTE, SOCK_RAW, AF_UNSPEC); setsockopt(route_socket, SOL_SOCKET, SO_USELOOPBACK, &(int){0}, sizeof(int)); +#ifdef RO_MSGFILTER + setsockopt(route_socket, PF_ROUTE, RO_MSGFILTER, , + sizeof(msgfilter)); +#endif sock_error = bind_current_routes(); if (sock_error != LDP_E_OK) {
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: christos Date: Tue Jan 10 21:02:38 UTC 2017 Modified Files: src/usr.sbin/ldpd: conffile.c Log Message: need To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/usr.sbin/ldpd/conffile.c 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/conffile.c diff -u src/usr.sbin/ldpd/conffile.c:1.11 src/usr.sbin/ldpd/conffile.c:1.12 --- src/usr.sbin/ldpd/conffile.c:1.11 Tue Nov 19 11:42:16 2013 +++ src/usr.sbin/ldpd/conffile.c Tue Jan 10 16:02:38 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: conffile.c,v 1.11 2013/11/19 16:42:16 christos Exp $ */ +/* $NetBSD: conffile.c,v 1.12 2017/01/10 21:02:38 christos Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -29,9 +29,12 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include +#include + #include #include -#include + #include #include #include
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: christos Date: Tue Nov 19 16:42:16 UTC 2013 Modified Files: src/usr.sbin/ldpd: conffile.c Log Message: CVE 1129617: negative arg To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/usr.sbin/ldpd/conffile.c 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/conffile.c diff -u src/usr.sbin/ldpd/conffile.c:1.10 src/usr.sbin/ldpd/conffile.c:1.11 --- src/usr.sbin/ldpd/conffile.c:1.10 Wed Nov 13 16:22:46 2013 +++ src/usr.sbin/ldpd/conffile.c Tue Nov 19 11:42:16 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: conffile.c,v 1.10 2013/11/13 21:22:46 christos Exp $ */ +/* $NetBSD: conffile.c,v 1.11 2013/11/19 16:42:16 christos Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -122,7 +122,8 @@ conf_parsefile(const char *fname) if (confh == -1 || fstat(confh, fs) == -1 || (mapped = mmap(NULL, fs.st_size, PROT_READ, MAP_SHARED, confh, 0)) == MAP_FAILED) { - close(confh); + if (confh != -1) + close(confh); return E_CONF_IO; }
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: christos Date: Wed Nov 13 21:20:21 UTC 2013 Modified Files: src/usr.sbin/ldpd: conffile.c Log Message: CID 1125876: File descriptor leak To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/usr.sbin/ldpd/conffile.c 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/conffile.c diff -u src/usr.sbin/ldpd/conffile.c:1.8 src/usr.sbin/ldpd/conffile.c:1.9 --- src/usr.sbin/ldpd/conffile.c:1.8 Fri Oct 18 10:14:14 2013 +++ src/usr.sbin/ldpd/conffile.c Wed Nov 13 16:20:21 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: conffile.c,v 1.8 2013/10/18 14:14:14 kefren Exp $ */ +/* $NetBSD: conffile.c,v 1.9 2013/11/13 21:20:21 christos Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -121,8 +121,10 @@ conf_parsefile(const char *fname) if (confh == -1 || fstat(confh, fs) == -1 || (mapped = mmap(NULL, fs.st_size, PROT_READ, MAP_SHARED, confh, 0)) - == MAP_FAILED) + == MAP_FAILED) { + close(confh); return E_CONF_IO; + } mapsize = fs.st_size; nextline = mapped;
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: christos Date: Wed Nov 13 21:22:46 UTC 2013 Modified Files: src/usr.sbin/ldpd: conffile.c Log Message: CID 1125875: Fix memory leak To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/ldpd/conffile.c 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/conffile.c diff -u src/usr.sbin/ldpd/conffile.c:1.9 src/usr.sbin/ldpd/conffile.c:1.10 --- src/usr.sbin/ldpd/conffile.c:1.9 Wed Nov 13 16:20:21 2013 +++ src/usr.sbin/ldpd/conffile.c Wed Nov 13 16:22:46 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: conffile.c,v 1.9 2013/11/13 21:20:21 christos Exp $ */ +/* $NetBSD: conffile.c,v 1.10 2013/11/13 21:22:46 christos Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -377,12 +377,14 @@ int Finterface(char *line) { char *ifname; - struct conf_interface *conf_if = calloc(1, sizeof(*conf_if)); + struct conf_interface *conf_if; char buf[LINEMAXSIZE]; - ifname = NextCommand(line); - if (conf_if == NULL || ifname == NULL) + if ((ifname = NextCommand(line)) == NULL) return -1; + if ((conf_if = calloc(1, sizeof(*conf_if))) == NULL) + return -1; + strlcpy(conf_if-if_name, ifname, IF_NAMESIZE); SLIST_INSERT_HEAD(coifs_head, conf_if, iflist);
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: mrg Date: Wed Oct 30 08:41:57 UTC 2013 Modified Files: src/usr.sbin/ldpd: socketops.c Log Message: ensure variables are initialised To generate a diff of this commit: cvs rdiff -u -r1.32 -r1.33 src/usr.sbin/ldpd/socketops.c 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/socketops.c diff -u src/usr.sbin/ldpd/socketops.c:1.32 src/usr.sbin/ldpd/socketops.c:1.33 --- src/usr.sbin/ldpd/socketops.c:1.32 Thu Oct 17 18:10:23 2013 +++ src/usr.sbin/ldpd/socketops.c Wed Oct 30 08:41:57 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: socketops.c,v 1.32 2013/10/17 18:10:23 kefren Exp $ */ +/* $NetBSD: socketops.c,v 1.33 2013/10/30 08:41:57 mrg Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -336,6 +336,7 @@ bind_socket(int s, int stype) assert (stype == AF_INET || stype == AF_INET6); + memset(su, 0, sizeof su); if (stype == AF_INET) { su.sin.sin_len = sizeof(su.sin); su.sin.sin_family = AF_INET;
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: wiz Date: Fri Oct 18 12:29:52 UTC 2013 Modified Files: src/usr.sbin/ldpd: ldpd.conf.5 Log Message: Sort SEE ALSO. Grammar consistency. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/ldpd/ldpd.conf.5 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/ldpd.conf.5 diff -u src/usr.sbin/ldpd/ldpd.conf.5:1.1 src/usr.sbin/ldpd/ldpd.conf.5:1.2 --- src/usr.sbin/ldpd/ldpd.conf.5:1.1 Fri Oct 18 10:49:19 2013 +++ src/usr.sbin/ldpd/ldpd.conf.5 Fri Oct 18 12:29:52 2013 @@ -1,4 +1,4 @@ -.\ $NetBSD: ldpd.conf.5,v 1.1 2013/10/18 10:49:19 kefren Exp $ +.\ $NetBSD: ldpd.conf.5,v 1.2 2013/10/18 12:29:52 wiz Exp $ .\ .\ Copyright (c) 2013 The NetBSD Foundation, Inc. .\ All rights reserved. @@ -79,7 +79,7 @@ will try to tag also the default route ( Interface block supports the following parameters .Bl -tag -width transport-address .It Li passive -Doesn't send hellos on interface +Don't send hellos on interface .It Li transport-address Transport INET4 address advertised in hellos sent on the mentioned interface .El @@ -87,7 +87,7 @@ Transport INET4 address advertised in he Neighbour block supports the following parameters .Bl -tag -width authenticate .It Li authenticate -Authenticates peer using TCP MD5 signature - needs options TCP_SIGNATURE. +Authenticate peer using TCP MD5 signature - needs options TCP_SIGNATURE. Default: off .El .Sh EXAMPLES @@ -118,8 +118,8 @@ neighbour 192.168.2.1 { } .Ed .Sh SEE ALSO -.Xr ldpd 8 , .Xr mpls 4 , +.Xr ldpd 8 .Sh HISTORY Support for .Nm
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Fri Oct 18 14:14:14 UTC 2013 Modified Files: src/usr.sbin/ldpd: conffile.c Log Message: sync behaviour with man page: accept spaces, empty lines and comments To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/ldpd/conffile.c 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/conffile.c diff -u src/usr.sbin/ldpd/conffile.c:1.7 src/usr.sbin/ldpd/conffile.c:1.8 --- src/usr.sbin/ldpd/conffile.c:1.7 Thu Oct 17 18:10:23 2013 +++ src/usr.sbin/ldpd/conffile.c Fri Oct 18 14:14:14 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: conffile.c,v 1.7 2013/10/17 18:10:23 kefren Exp $ */ +/* $NetBSD: conffile.c,v 1.8 2013/10/18 14:14:14 kefren Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include arpa/inet.h #include netinet/in.h - +#include sys/mman.h #include ctype.h #include fcntl.h #include stdlib.h @@ -44,13 +44,15 @@ #define NextCommand(x) strsep(x, ) #define LINEMAXSIZE 1024 +char *mapped, *nextline; +size_t mapsize; + extern int ldp_hello_time, ldp_keepalive_time, ldp_holddown_time, command_port, min_label, max_label, no_default_route, loop_detection; -int confh; struct in_addr conf_ldp_id; static int conf_dispatch(char*); -static int conf_readline(char*, size_t); +static char * conf_getlinelimit(void); static int checkeol(char*); static int Fhellotime(char*); static int Fport(char*); @@ -108,52 +110,59 @@ static int parseline; int conf_parsefile(const char *fname) { - char buf[LINEMAXSIZE + 1]; + char line[LINEMAXSIZE+1]; + struct stat fs; SLIST_INIT(conei_head); SLIST_INIT(coifs_head); conf_ldp_id.s_addr = 0; - confh = open(fname, O_RDONLY, 0); + int confh = open(fname, O_RDONLY, 0); - if (confh == -1) + if (confh == -1 || fstat(confh, fs) == -1 || + (mapped = mmap(NULL, fs.st_size, PROT_READ, MAP_SHARED, confh, 0)) + == MAP_FAILED) return E_CONF_IO; - for (parseline = 1; conf_readline(buf, sizeof(buf)) = 0; parseline++) - if (conf_dispatch(buf) != 0) { - close(confh); - return parseline; - } - + mapsize = fs.st_size; + nextline = mapped; + for (parseline = 1; ; parseline++) { + char *prev = nextline; + if ((nextline = conf_getlinelimit()) == NULL) + break; + while (isspace((int)*prev) != 0 prev nextline) + prev++; + if (nextline - prev 2) + continue; + else if (nextline - prev LINEMAXSIZE) + goto parerr; + memcpy(line, prev, nextline - prev); + if (line[0] == '#') + continue; + else + line[nextline - prev] = '\0'; + if (conf_dispatch(line) != 0) + goto parerr; + } + munmap(mapped, mapsize); close(confh); return 0; +parerr: + munmap(mapped, mapsize); + close(confh); + return parseline; } -/* - * Reads a line from config file - */ -int -conf_readline(char *buf, size_t bufsize) +char * +conf_getlinelimit(void) { - size_t i; + char *p = nextline; - for (i = 0; i bufsize; i++) { - if (read(confh, buf[i], 1) != 1) { - if (i == 0) -return E_CONF_IO; - break; - } - if (buf[i] == '\n') - break; - if (i == 0 isspace((unsigned char)buf[i]) != 0) { - i--; - continue; - } - } - if (i == bufsize) - return E_CONF_MEM; - buf[i] = '\0'; - return i; + if (nextline mapped || (size_t)(nextline - mapped) = mapsize) + return NULL; + + for (p = nextline; *p != '\n' (size_t)(p - mapped) mapsize; p++); + return p + 1; } /* @@ -179,7 +188,7 @@ conf_dispatch(char *line) else if (matched 1) return E_CONF_AMBIGUOUS; - if (checkeol(nline) != 0) + if (nline == NULL || checkeol(nline) != 0) return E_CONF_PARAM; return main_commands[last_match].func(nline); } @@ -193,6 +202,10 @@ int checkeol(char *line) { size_t len = strlen(line); + if (len 0 line[len - 1] == '\n') { + line[len - 1] = '\0'; + len--; + } if (len 0 line[len - 1] == ';') { line[len - 1] = '\0'; return 0; @@ -289,7 +302,7 @@ Fneighbour(char *line) char *peer; struct conf_neighbour *nei; struct in_addr ad; - char buf[1024]; + char buf[LINEMAXSIZE]; peer = NextCommand(line); if (inet_pton(AF_INET, peer, ad) != 1) @@ -301,10 +314,21 @@ Fneighbour(char *line) nei-address.s_addr = ad.s_addr; SLIST_INSERT_HEAD(conei_head, nei, neilist); - while (conf_readline(buf, sizeof(buf)) = 0) { + for ( ; ; ) { + char *prev = nextline; parseline++; - if (buf[0] == '}') - return 0; + nextline = conf_getlinelimit(); + if (nextline == NULL || (size_t)(nextline - prev) LINEMAXSIZE) + return -1; + while (isspace((int)*prev) != 0 prev nextline) + prev++; + memcpy(buf, prev, nextline - prev); + if (nextline - prev 2 || buf[0] == '#') + continue; + else if (buf[0] == '}') + break; + else + buf[nextline - prev] = '\0'; if (Gneighbour(nei, buf) == -1) return -1; } @@ -352,7 +376,7 @@ Finterface(char *line) { char *ifname; struct conf_interface *conf_if = calloc(1,
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Thu Oct 17 18:10:23 UTC 2013 Modified Files: src/usr.sbin/ldpd: conffile.c conffile.h socketops.c Log Message: allow setting transport addresses for interfaces into config file also move passive-interface functionality under interface block report the correct line for config parsing errors To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/ldpd/conffile.c cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/ldpd/conffile.h cvs rdiff -u -r1.31 -r1.32 src/usr.sbin/ldpd/socketops.c 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/conffile.c diff -u src/usr.sbin/ldpd/conffile.c:1.6 src/usr.sbin/ldpd/conffile.c:1.7 --- src/usr.sbin/ldpd/conffile.c:1.6 Thu Jul 11 10:46:19 2013 +++ src/usr.sbin/ldpd/conffile.c Thu Oct 17 18:10:23 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: conffile.c,v 1.6 2013/07/11 10:46:19 kefren Exp $ */ +/* $NetBSD: conffile.c,v 1.7 2013/10/17 18:10:23 kefren Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -63,13 +63,21 @@ static int Fneighbour(char*); static int Gneighbour(struct conf_neighbour *, char *); static int Fnodefault(char*); static int Floopdetection(char*); -static int Fpassiveif(char*); +static int Finterface(char*); +static int Ginterface(struct conf_interface *, char *); +static int Ipassive(struct conf_interface *, char *); +static int Itaddr(struct conf_interface *, char *); struct conf_func { char com[64]; int (* func)(char *); }; +struct intf_func { + char com[64]; + int (* func)(struct conf_interface *, char *); +}; + struct conf_func main_commands[] = { { hello-time, Fhellotime }, { keepalive-time, Fkeepalive }, @@ -77,26 +85,33 @@ struct conf_func main_commands[] = { { command-port, Fport }, { min-label, Fminlabel }, { max-label, Fmaxlabel }, - { LDP-ID, Fldpid }, + { ldp-id, Fldpid }, { neighbor, Fneighbour }, { neighbour, Fneighbour }, { no-default-route, Fnodefault }, { loop-detection, Floopdetection }, - { passive-if, Fpassiveif }, + { interface, Finterface }, { , NULL }, }; +struct intf_func intf_commands[] = { + { passive, Ipassive }, + { transport-address, Itaddr }, + { , NULL }, +}; + +static int parseline; + /* * Parses config file */ int conf_parsefile(const char *fname) { - int i; char buf[LINEMAXSIZE + 1]; SLIST_INIT(conei_head); - SLIST_INIT(passifs_head); + SLIST_INIT(coifs_head); conf_ldp_id.s_addr = 0; confh = open(fname, O_RDONLY, 0); @@ -104,10 +119,10 @@ conf_parsefile(const char *fname) if (confh == -1) return E_CONF_IO; - for (i = 1; conf_readline(buf, sizeof(buf)) = 0; i++) + for (parseline = 1; conf_readline(buf, sizeof(buf)) = 0; parseline++) if (conf_dispatch(buf) != 0) { close(confh); - return i; + return parseline; } close(confh); @@ -155,7 +170,7 @@ conf_dispatch(char *line) command = NextCommand(nline); for (i = 0; main_commands[i].func != NULL; i++) if (strncasecmp(main_commands[i].com, command, - strlen(command)) == 0) { + strlen(main_commands[i].com)) == 0) { matched++; last_match = i; } @@ -287,6 +302,7 @@ Fneighbour(char *line) SLIST_INSERT_HEAD(conei_head, nei, neilist); while (conf_readline(buf, sizeof(buf)) = 0) { + parseline++; if (buf[0] == '}') return 0; if (Gneighbour(nei, buf) == -1) @@ -328,15 +344,59 @@ Floopdetection(char *line) return 0; } +/* + * Interface sub-commands + */ int -Fpassiveif(char *line) +Finterface(char *line) { - struct passive_if *pif; + char *ifname; + struct conf_interface *conf_if = calloc(1, sizeof(*conf_if)); + char buf[1024]; - if (strlen(line) IF_NAMESIZE - 1) - return E_CONF_PARAM; - pif = calloc(1, sizeof(*pif)); - strlcpy(pif-if_name, line, IF_NAMESIZE); - SLIST_INSERT_HEAD(passifs_head, pif, listentry); + ifname = NextCommand(line); + if (conf_if == NULL || ifname == NULL) + return -1; + strlcpy(conf_if-if_name, ifname, IF_NAMESIZE); + SLIST_INSERT_HEAD(coifs_head, conf_if, iflist); + + while (conf_readline(buf, sizeof(buf)) = 0) { + parseline++; + if (buf[0] == '}') + return 0; + if (Ginterface(conf_if, buf) == -1) + return -1; + } + return -1; +} + +int +Ginterface(struct conf_interface *conf_if, char *buf) +{ + int i; + + for (i = 0; intf_commands[i].func != NULL; i++) + if (strncasecmp(buf, intf_commands[i].com, + strlen(intf_commands[i].com)) == 0) + return intf_commands[i].func(conf_if, buf + + strlen(intf_commands[i].com) + 1); + /* command not found */ + return -1; +} + +/* sets transport address */ +int +Itaddr(struct conf_interface *conf_if, char *buf) +{ + if (inet_pton(AF_INET, buf, conf_if-tr_addr) != 1) + return -1; + return 0; +} + +/* sets passive-interface on */ +int +Ipassive(struct conf_interface *conf_if, char *buf) +{ + conf_if-passive = 1; return 0; } Index: src/usr.sbin/ldpd/conffile.h diff -u
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Sat Oct 12 18:55:40 UTC 2013 Modified Files: src/usr.sbin/ldpd: mpls_routes.c Log Message: zeroize the rest of the comparable struct before adding it to the rb tree To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/usr.sbin/ldpd/mpls_routes.c 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/mpls_routes.c diff -u src/usr.sbin/ldpd/mpls_routes.c:1.22 src/usr.sbin/ldpd/mpls_routes.c:1.23 --- src/usr.sbin/ldpd/mpls_routes.c:1.22 Wed Jul 31 06:58:23 2013 +++ src/usr.sbin/ldpd/mpls_routes.c Sat Oct 12 18:55:40 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: mpls_routes.c,v 1.22 2013/07/31 06:58:23 kefren Exp $ */ +/* $NetBSD: mpls_routes.c,v 1.23 2013/10/12 18:55:40 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -648,6 +648,8 @@ check_route(struct rt_msg * rg, uint rle so_pref-sa.sa_family = AF_INET; so_pref-sa.sa_len = sizeof(struct sockaddr_in); + so_pref-sin.sin_port = 0; + memset(so_pref-sin.sin_zero, 0, sizeof(so_pref-sin.sin_zero)); if (rg-m_rtm.rtm_flags RTF_CLONING) so_gate = NULL;
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Fri Aug 2 07:29:56 UTC 2013 Modified Files: src/usr.sbin/ldpd: ldp_command.c ldp_peer.c ldp_peer.h mpls_interface.c Log Message: Use rbtree for storing peers FEC label bindings To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/usr.sbin/ldpd/ldp_command.c cvs rdiff -u -r1.15 -r1.16 src/usr.sbin/ldpd/ldp_peer.c cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/ldpd/ldp_peer.h cvs rdiff -u -r1.12 -r1.13 src/usr.sbin/ldpd/mpls_interface.c 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/ldp_command.c diff -u src/usr.sbin/ldpd/ldp_command.c:1.13 src/usr.sbin/ldpd/ldp_command.c:1.14 --- src/usr.sbin/ldpd/ldp_command.c:1.13 Wed Jul 31 06:58:23 2013 +++ src/usr.sbin/ldpd/ldp_command.c Fri Aug 2 07:29:56 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: ldp_command.c,v 1.13 2013/07/31 06:58:23 kefren Exp $ */ +/* $NetBSD: ldp_command.c,v 1.14 2013/08/02 07:29:56 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -481,12 +481,12 @@ int show_labels(int s, char *recvspace) { struct ldp_peer *p; - struct label_mapping *lm; + struct label_mapping *lm = NULL; SLIST_FOREACH(p, ldp_peer_head, peers) { if (p-state != LDP_PEER_ESTABLISHED) continue; - SLIST_FOREACH(lm, p-label_mapping_head, mappings) { + while ((lm = ldp_peer_lm_right(p, lm)) != NULL) { char lma[256]; /* XXX: TODO */ if (lm-address.sa.sa_family != AF_INET) Index: src/usr.sbin/ldpd/ldp_peer.c diff -u src/usr.sbin/ldpd/ldp_peer.c:1.15 src/usr.sbin/ldpd/ldp_peer.c:1.16 --- src/usr.sbin/ldpd/ldp_peer.c:1.15 Sat Jul 20 05:16:08 2013 +++ src/usr.sbin/ldpd/ldp_peer.c Fri Aug 2 07:29:56 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: ldp_peer.c,v 1.15 2013/07/20 05:16:08 kefren Exp $ */ +/* $NetBSD: ldp_peer.c,v 1.16 2013/08/02 07:29:56 kefren Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -41,6 +41,7 @@ #include fcntl.h #include stdlib.h #include strings.h +#include stddef.h #include stdio.h #include unistd.h @@ -55,6 +56,17 @@ extern int ldp_holddown_time; +static struct label_mapping *ldp_peer_get_lm(struct ldp_peer *, +const struct sockaddr *, uint); + +static int mappings_compare(void *, const void *, const void *); +static rb_tree_ops_t mappings_tree_ops = { + .rbto_compare_nodes = mappings_compare, + .rbto_compare_key = mappings_compare, + .rbto_node_offset = offsetof(struct label_mapping, mappings_node), + .rbto_context = NULL +}; + void ldp_peer_init(void) { @@ -69,6 +81,28 @@ sockaddr_cmp(const struct sockaddr *a, c return -1; return memcmp(a, b, a-sa_len); } + +static int +mappings_compare(void *context, const void *node1, const void *node2) +{ + const struct label_mapping *l1 = node1, *l2 = node2; + int ret; + + if (__predict_false(l1-address.sa.sa_family != + l2-address.sa.sa_family)) + return l1-address.sa.sa_family l2-address.sa.sa_family ? + 1 : -1; + + assert(l1-address.sa.sa_len == l2-address.sa.sa_len); + if ((ret = memcmp(l1-address.sa, l2-address.sa, l1-address.sa.sa_len)) != 0) + return ret; + + if (__predict_false(l1-prefix != l2-prefix)) + return l1-prefix l2-prefix ? 1 : -1; + + return 0; +} + /* * soc should be 1 if there is already a TCP socket for this else we'll * initiate a new one @@ -150,7 +184,7 @@ ldp_peer_new(const struct in_addr * ldp_ set_ttl(p-socket); } SLIST_INIT(p-ldp_peer_address_head); - SLIST_INIT(p-label_mapping_head); + rb_tree_init(p-label_mapping_tree, mappings_tree_ops); p-timeout = p-holdtime; sopts = fcntl(p-socket, F_GETFL); @@ -449,7 +483,7 @@ ldp_peer_add_mapping(struct ldp_peer * p lma-prefix = prefix; lma-label = label; - SLIST_INSERT_HEAD(p-label_mapping_head, lma, mappings); + rb_tree_insert_node(p-label_mapping_tree, lma); return LDP_E_OK; } @@ -460,34 +494,28 @@ ldp_peer_delete_mapping(struct ldp_peer { struct label_mapping *lma; - if (!a) + if (a == NULL || (lma = ldp_peer_get_lm(p, a, prefix)) == NULL) return LDP_E_NOENT; - lma = ldp_peer_get_lm(p, a, prefix); - if (!lma) - return LDP_E_NOENT; - - SLIST_REMOVE(p-label_mapping_head, lma, label_mapping, mappings); + rb_tree_remove_node(p-label_mapping_tree, lma); free(lma); return LDP_E_OK; } -struct label_mapping * -ldp_peer_get_lm(const struct ldp_peer * p, const struct sockaddr * a, +static struct label_mapping * +ldp_peer_get_lm(struct ldp_peer * p, const struct sockaddr * a, uint prefix) { - struct label_mapping *rv; + struct label_mapping rv; - if (!p) - return NULL; - - SLIST_FOREACH(rv, p-label_mapping_head, mappings) - if (rv-prefix == prefix sockaddr_cmp(a, rv-address.sa)==0) - break; + assert(a-sa_len = sizeof(union sockunion)); - return rv; + memset(rv, 0, sizeof(rv)); + memcpy(rv.address.sa, a, a-sa_len); + rv.prefix = prefix; + return rb_tree_find_node(p-label_mapping_tree, rv); } void @@ -495,9 +523,8 @@
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: martin Date: Fri Aug 2 16:51:25 UTC 2013 Modified Files: src/usr.sbin/ldpd: mpls_routes.h Log Message: Do not pack struct rt_msg - this voids the alignement restrictions and causes crashes on alignemen critical archs. From Matt Thomas. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/ldpd/mpls_routes.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/mpls_routes.h diff -u src/usr.sbin/ldpd/mpls_routes.h:1.6 src/usr.sbin/ldpd/mpls_routes.h:1.7 --- src/usr.sbin/ldpd/mpls_routes.h:1.6 Thu Jul 18 11:45:36 2013 +++ src/usr.sbin/ldpd/mpls_routes.h Fri Aug 2 16:51:25 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: mpls_routes.h,v 1.6 2013/07/18 11:45:36 kefren Exp $ */ +/* $NetBSD: mpls_routes.h,v 1.7 2013/08/02 16:51:25 martin Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -57,7 +57,7 @@ union sockunion { struct rt_msg { struct rt_msghdr m_rtm; charm_space[512]; -} __packed; +}; union sockunion * make_inet_union(const char *); union sockunion * make_mpls_union(uint32_t);
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Wed Jul 31 06:58:23 UTC 2013 Modified Files: src/usr.sbin/ldpd: label.c label.h ldp_command.c main.c mpls_routes.c tlv_stack.c Log Message: Store local bindings in a rbtree To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/usr.sbin/ldpd/label.c cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/ldpd/label.h cvs rdiff -u -r1.12 -r1.13 src/usr.sbin/ldpd/ldp_command.c \ src/usr.sbin/ldpd/tlv_stack.c cvs rdiff -u -r1.8 -r1.9 src/usr.sbin/ldpd/main.c cvs rdiff -u -r1.21 -r1.22 src/usr.sbin/ldpd/mpls_routes.c 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/label.c diff -u src/usr.sbin/ldpd/label.c:1.10 src/usr.sbin/ldpd/label.c:1.11 --- src/usr.sbin/ldpd/label.c:1.10 Wed Jul 24 09:05:53 2013 +++ src/usr.sbin/ldpd/label.c Wed Jul 31 06:58:23 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: label.c,v 1.10 2013/07/24 09:05:53 kefren Exp $ */ +/* $NetBSD: label.c,v 1.11 2013/07/31 06:58:23 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -32,6 +32,7 @@ #include netmpls/mpls.h #include assert.h +#include stddef.h #include stdlib.h #include string.h @@ -41,12 +42,45 @@ #include label.h #include ldp_errors.h -int min_label = MIN_LABEL, max_label = MAX_LABEL; +static int labels_compare(void*, const void*, const void*); + +int min_label = MIN_LABEL, max_label = MAX_LABEL; + +static rb_tree_t labels_tree; +static const rb_tree_ops_t tree_ops = { + .rbto_compare_nodes = labels_compare, + .rbto_compare_key = labels_compare, + .rbto_node_offset = offsetof(struct label, lbtree), + .rbto_context = NULL +}; void label_init() { - SLIST_INIT(label_head); + + rb_tree_init(labels_tree, tree_ops); +} + +static int +labels_compare(void *context, const void *node1, const void *node2) +{ + const struct label *l1 = node1, *l2 = node2; + int ret; + + if (__predict_false(l1-so_dest.sa.sa_family != + l2-so_dest.sa.sa_family)) + return l1-so_dest.sa.sa_family l2-so_dest.sa.sa_family ? + 1 : -1; + + assert(l1-so_dest.sa.sa_len == l2-so_dest.sa.sa_len); + assert(l1-so_pref.sa.sa_len == l2-so_pref.sa.sa_len); + + if ((ret = memcmp(l1-so_dest.sa, l2-so_dest.sa, + l1-so_dest.sa.sa_len)) != 0) + return ret; + else + return memcmp(l1-so_pref.sa, l2-so_pref.sa, + l1-so_pref.sa.sa_len); } /* @@ -85,7 +119,8 @@ label_add(const union sockunion * so_des l-label = label; l-host = host; - SLIST_INSERT_HEAD(label_head, l, labels); + if (rb_tree_insert_node(labels_tree, l) != l) + fatalp(label already in tree); strlcpy(spreftmp, satos(so_pref-sa), INET_ADDRSTRLEN); warnp([label_add] added binding %d for %s/%s\n, l-binding, @@ -102,7 +137,7 @@ label_del(struct label * l) { warnp([label_del] deleted binding %d for %s\n, l-binding, satos(l-so_dest.sa)); - SLIST_REMOVE(label_head, l, label, labels); + rb_tree_remove_node(labels_tree, l); free(l); } @@ -148,15 +183,13 @@ label_reattach_route(struct label *l, in struct label* label_get(const union sockunion *sodest, const union sockunion *sopref) { - struct label *l; + struct label l; - SLIST_FOREACH (l, label_head, labels) - if (sodest-sin.sin_addr.s_addr == - l-so_dest.sin.sin_addr.s_addr - sopref-sin.sin_addr.s_addr == - l-so_pref.sin.sin_addr.s_addr) - return l; - return NULL; + memset(l, 0, sizeof(l)); + memcpy(l.so_dest, sodest, sodest-sa.sa_len); + memcpy(l.so_pref, sopref, sopref-sa.sa_len); + + return rb_tree_find_node(labels_tree, l); } /* @@ -168,7 +201,7 @@ label_reattach_all_peer_labels(const str { struct label *l; - SLIST_FOREACH(l, label_head, labels) + RB_TREE_FOREACH(l, labels_tree) if (l-p == p) label_reattach_route(l, readd); } @@ -182,12 +215,17 @@ del_all_peer_labels(const struct ldp_pee { struct label *l, *lnext; - SLIST_FOREACH_SAFE(l, label_head, labels, lnext) { + RB_TREE_FOREACH(l, labels_tree) { +back_delete: if(l-p != p) continue; label_reattach_route(l, readd); + lnext = rb_tree_iterate(labels_tree, l, RB_DIR_RIGHT); label_del(l); - SLIST_REMOVE(label_head, l, label, labels); + if (lnext == NULL) + break; + l = lnext; + goto back_delete; } } @@ -199,11 +237,10 @@ label_del_by_binding(uint32_t binding, i { struct label *l; - SLIST_FOREACH(l, label_head, labels) + RB_TREE_FOREACH(l, labels_tree) if ((uint32_t)l-binding == binding) { label_reattach_route(l, readd); label_del(l); - SLIST_REMOVE(label_head, l, label, labels); break; } } @@ -238,7 +275,7 @@ get_free_local_label() int lbl; for (lbl = min_label; lbl = max_label; lbl++) { - SLIST_FOREACH(l, label_head, labels) + RB_TREE_FOREACH(l, labels_tree) if (l-binding == lbl) break; if (l == NULL) @@ -267,13 +304,22 @@ label_check_assoc(struct ldp_peer *p) struct label *l; struct ldp_peer_address *wp; - SLIST_FOREACH (l, label_head,
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Sat Jul 27 14:35:41 UTC 2013 Modified Files: src/usr.sbin/ldpd: mpls_routes.c socketops.c Log Message: check route messages sizes more carefully cache pid treat every message at a time, even if there are more messages to read interpret also cloning routes The latter two should fix the ldp_regen test To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/usr.sbin/ldpd/mpls_routes.c cvs rdiff -u -r1.30 -r1.31 src/usr.sbin/ldpd/socketops.c 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/mpls_routes.c diff -u src/usr.sbin/ldpd/mpls_routes.c:1.20 src/usr.sbin/ldpd/mpls_routes.c:1.21 --- src/usr.sbin/ldpd/mpls_routes.c:1.20 Wed Jul 24 09:05:53 2013 +++ src/usr.sbin/ldpd/mpls_routes.c Sat Jul 27 14:35:41 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: mpls_routes.c,v 1.20 2013/07/24 09:05:53 kefren Exp $ */ +/* $NetBSD: mpls_routes.c,v 1.21 2013/07/27 14:35:41 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -62,6 +62,7 @@ int rt_seq = 200; int dont_catch = 0; extern int no_default_route; extern int debug_f, warn_f; +static int my_pid = 0; struct rt_msg replay_rt[REPLAY_MAX]; int replay_index = 0; @@ -588,7 +589,8 @@ check_route(struct rt_msg * rg, uint rle gate[0] = 0; pref[0] = 0; - if (rlen 3 || rg-m_rtm.rtm_version != RTM_VERSION) + if (rlen = offsetof(struct rt_msghdr, rtm_type) || + rg-m_rtm.rtm_version != RTM_VERSION) return LDP_E_ROUTE_ERROR; if (rg-m_rtm.rtm_type == RTM_NEWADDR || @@ -598,13 +600,23 @@ check_route(struct rt_msg * rg, uint rle size_cp = sizeof(struct rt_msghdr); CHECK_MINSA; - if (rg-m_rtm.rtm_pid == getpid() || - ((rg-m_rtm.rtm_flags RTF_DONE) == 0)) + if (my_pid == 0) + my_pid = getpid(); + assert(my_pid != 0); + + if (rg-m_rtm.rtm_pid == my_pid || + (rg-m_rtm.rtm_pid != 0 (rg-m_rtm.rtm_flags RTF_DONE) == 0) || + (rg-m_rtm.rtm_type != RTM_ADD + rg-m_rtm.rtm_type != RTM_DELETE + rg-m_rtm.rtm_type != RTM_CHANGE)) return LDP_E_OK; debugp(Check route triggered by PID: %d\n, rg-m_rtm.rtm_pid); - so_dest = (union sockunion *) rg-m_space; + if (rg-m_rtm.rtm_addrs RTA_DST) + so_dest = (union sockunion *) rg-m_space; + else + return LDP_E_ROUTE_ERROR; if (so_dest-sa.sa_family != AF_INET) return LDP_E_OK;/* We don't care about non-IP changes */ @@ -613,8 +625,9 @@ check_route(struct rt_msg * rg, uint rle if (rg-m_rtm.rtm_addrs RTA_GATEWAY) { GETNEXT(so_gate, so_dest); - if ((so_gate-sa.sa_family != AF_INET) - (so_gate-sa.sa_family != AF_MPLS)) + if ((rg-m_rtm.rtm_flags RTF_CLONING) == 0 + so_gate-sa.sa_family != AF_INET + so_gate-sa.sa_family != AF_MPLS) return LDP_E_OK; } if (rg-m_rtm.rtm_addrs RTA_NETMASK) { @@ -636,6 +649,9 @@ check_route(struct rt_msg * rg, uint rle so_pref-sa.sa_family = AF_INET; so_pref-sa.sa_len = sizeof(struct sockaddr_in); + if (rg-m_rtm.rtm_flags RTF_CLONING) + so_gate = NULL; + switch (rg-m_rtm.rtm_type) { case RTM_CHANGE: lab = label_get(so_dest, so_pref); Index: src/usr.sbin/ldpd/socketops.c diff -u src/usr.sbin/ldpd/socketops.c:1.30 src/usr.sbin/ldpd/socketops.c:1.31 --- src/usr.sbin/ldpd/socketops.c:1.30 Sat Jul 20 05:16:08 2013 +++ src/usr.sbin/ldpd/socketops.c Sat Jul 27 14:35:41 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: socketops.c,v 1.30 2013/07/20 05:16:08 kefren Exp $ */ +/* $NetBSD: socketops.c,v 1.31 2013/07/27 14:35:41 kefren Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -903,10 +903,15 @@ the_big_loop(void) new_peer_connection(); else if (pfd[i].fd == route_socket) { struct rt_msg xbuf; - int l; + int l, rtmlen = sizeof(xbuf); + /* Read at least rtm_msglen */ + l = recv(route_socket, xbuf, + sizeof(u_short), MSG_PEEK); + if (l == sizeof(u_short)) + rtmlen = xbuf.m_rtm.rtm_msglen; do { - l = read(route_socket, xbuf, - sizeof(xbuf)); + l = recv(route_socket, xbuf, + rtmlen, MSG_WAITALL); } while ((l == -1) (errno == EINTR)); if (l == -1)
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Thu Jul 25 08:40:30 UTC 2013 Modified Files: src/usr.sbin/ldpd: main.c Log Message: * don't request explicitly for uid 0 as various system policies may make that unnecessary * correct the mplsif message. We don't need an IP address assigned on it anymore To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/ldpd/main.c 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/main.c diff -u src/usr.sbin/ldpd/main.c:1.7 src/usr.sbin/ldpd/main.c:1.8 --- src/usr.sbin/ldpd/main.c:1.7 Mon Nov 12 18:39:00 2012 +++ src/usr.sbin/ldpd/main.c Thu Jul 25 08:40:30 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.7 2012/11/12 18:39:00 kefren Exp $ */ +/* $NetBSD: main.c,v 1.8 2013/07/25 08:40:30 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -101,10 +101,6 @@ main(int argc, char *argv[]) return EXIT_FAILURE; break; } - if (geteuid()) { - fatalp(You have to run this as ROOT\n); - return EXIT_FAILURE; - } cpf = conf_parsefile(conffile); if (cpf 0 strcmp(conffile, CONFFILE)) { @@ -123,8 +119,8 @@ main(int argc, char *argv[]) strlcpy(my_ldp_id, inet_ntoa(conf_ldp_id), INET_ADDRSTRLEN); if (mplssockaddr.sa_len == 0) { - fatalp(You need one mpls interface up and an IP - address set for it\n); + fatalp(FATAL: Create an mpls interface using ifconfig\n + e.g. ifconfig mpls0 create up\n); return EXIT_FAILURE; } if (mpls_start_ldp() == -1)
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Wed Jul 24 09:05:53 UTC 2013 Modified Files: src/usr.sbin/ldpd: label.c label.h mpls_interface.c mpls_routes.c Log Message: * use a flag in label struct in order to determine if we should treat the associated routes using RTF_HOST * clean the mess in flush_mpls_routes that could result in accessing uninitialized memory To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/ldpd/label.c cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/ldpd/label.h cvs rdiff -u -r1.11 -r1.12 src/usr.sbin/ldpd/mpls_interface.c cvs rdiff -u -r1.19 -r1.20 src/usr.sbin/ldpd/mpls_routes.c 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/label.c diff -u src/usr.sbin/ldpd/label.c:1.9 src/usr.sbin/ldpd/label.c:1.10 --- src/usr.sbin/ldpd/label.c:1.9 Thu Jul 18 11:45:36 2013 +++ src/usr.sbin/ldpd/label.c Wed Jul 24 09:05:53 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: label.c,v 1.9 2013/07/18 11:45:36 kefren Exp $ */ +/* $NetBSD: label.c,v 1.10 2013/07/24 09:05:53 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -55,7 +55,7 @@ label_init() struct label * label_add(const union sockunion * so_dest, const union sockunion * so_pref, const union sockunion * so_gate, uint32_t binding, - const struct ldp_peer * p, uint32_t label) + const struct ldp_peer * p, uint32_t label, bool host) { struct label *l; char spreftmp[INET_ADDRSTRLEN]; @@ -83,6 +83,7 @@ label_add(const union sockunion * so_des l-binding = get_free_local_label(); l-p = p; l-label = label; + l-host = host; SLIST_INSERT_HEAD(label_head, l, labels); @@ -125,12 +126,13 @@ label_reattach_route(struct label *l, in if (readd == REATT_INET_CHANGE) { /* Delete the tagged route and re-add IPv4 route */ delete_route(l-so_dest, - l-so_pref.sa.sa_len != 0 ? l-so_pref : NULL, NO_FREESO); + l-host ? NULL : l-so_pref, NO_FREESO); add_route(l-so_dest, - l-so_pref.sa.sa_len != 0 ? l-so_pref : NULL, l-so_gate, + l-host ? NULL : l-so_pref, l-so_gate, NULL, NULL, NO_FREESO, RTM_READD); } else if (readd == REATT_INET_DEL) - delete_route(l-so_dest, l-so_pref, NO_FREESO); + delete_route(l-so_dest, l-host ? NULL : l-so_pref, + NO_FREESO); /* Deletes the MPLS route */ if (l-binding = min_label) Index: src/usr.sbin/ldpd/label.h diff -u src/usr.sbin/ldpd/label.h:1.6 src/usr.sbin/ldpd/label.h:1.7 --- src/usr.sbin/ldpd/label.h:1.6 Thu Jul 18 11:45:36 2013 +++ src/usr.sbin/ldpd/label.h Wed Jul 24 09:05:53 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: label.h,v 1.6 2013/07/18 11:45:36 kefren Exp $ */ +/* $NetBSD: label.h,v 1.7 2013/07/24 09:05:53 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -51,6 +51,7 @@ struct label { union sockunion so_dest, so_pref, so_gate; int binding, label; + bool host; /* change routes using RTF_HOST */ const struct ldp_peer *p; SLIST_ENTRY(label) labels; }; @@ -58,7 +59,8 @@ SLIST_HEAD(,label) label_head; voidlabel_init(void); struct label * label_add(const union sockunion *, const union sockunion *, - const union sockunion *, uint32_t, const struct ldp_peer *, uint32_t); + const union sockunion *, uint32_t, const struct ldp_peer *, uint32_t, + bool); voidlabel_del(struct label *); voiddel_all_peer_labels(const struct ldp_peer*, int); void label_reattach_all_peer_labels(const struct ldp_peer*, int); Index: src/usr.sbin/ldpd/mpls_interface.c diff -u src/usr.sbin/ldpd/mpls_interface.c:1.11 src/usr.sbin/ldpd/mpls_interface.c:1.12 --- src/usr.sbin/ldpd/mpls_interface.c:1.11 Thu Jul 18 11:45:36 2013 +++ src/usr.sbin/ldpd/mpls_interface.c Wed Jul 24 09:05:53 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: mpls_interface.c,v 1.11 2013/07/18 11:45:36 kefren Exp $ */ +/* $NetBSD: mpls_interface.c,v 1.12 2013/07/24 09:05:53 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -138,24 +138,9 @@ mpls_add_label(struct label *lab) fatalp(Out of memory\n); return LDP_E_MEMORY; } -/* - if (so_oldifa != NULL) { - so_ifa = malloc(sizeof(*so_ifa)); - if (so_ifa == NULL) { - free(so_dest); - if (so_pref != NULL) -free(so_pref); - free(so_tag); - free(so_nexthop); - fatalp(Out of memory\n); - return LDP_E_MEMORY; - } - memcpy(so_ifa, so_oldifa, so_oldifa-sa.sa_len); - } else - so_ifa = NULL; -*/ - if (add_route(lab-so_dest, lab-so_pref, lab-so_gate, so_ifa, - so_tag, NO_FREESO, RTM_CHANGE) != LDP_E_OK) { + + if (add_route(lab-so_dest, lab-host ? NULL : lab-so_pref, + lab-so_gate, so_ifa, so_tag, NO_FREESO, RTM_CHANGE) != LDP_E_OK){ free(so_tag); fatalp([mpls_add_label]: INET route failure\n); return LDP_E_ROUTE_ERROR; Index: src/usr.sbin/ldpd/mpls_routes.c diff -u src/usr.sbin/ldpd/mpls_routes.c:1.19 src/usr.sbin/ldpd/mpls_routes.c:1.20 --- src/usr.sbin/ldpd/mpls_routes.c:1.19
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Sat Jul 20 05:16:08 UTC 2013 Modified Files: src/usr.sbin/ldpd: fsm.c ldp_peer.c ldp_peer.h mpls_routes.c socketops.c tlv_stack.c Log Message: don't connect on first hello, there are chances that ours is not seen yet setproctitle with ldp id - useful for rump kernels testing fix a memory leak in ldp_peer_new don't holddown if already holded down peer sockets are now non-blocking connected routes deletes are now processed check if peer is connected before attempting to sending label mappings To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/usr.sbin/ldpd/fsm.c cvs rdiff -u -r1.14 -r1.15 src/usr.sbin/ldpd/ldp_peer.c cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/ldpd/ldp_peer.h cvs rdiff -u -r1.18 -r1.19 src/usr.sbin/ldpd/mpls_routes.c cvs rdiff -u -r1.29 -r1.30 src/usr.sbin/ldpd/socketops.c cvs rdiff -u -r1.11 -r1.12 src/usr.sbin/ldpd/tlv_stack.c 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.13 src/usr.sbin/ldpd/fsm.c:1.14 --- src/usr.sbin/ldpd/fsm.c:1.13 Fri Jul 12 08:55:52 2013 +++ src/usr.sbin/ldpd/fsm.c Sat Jul 20 05:16:08 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: fsm.c,v 1.13 2013/07/12 08:55:52 kefren Exp $ */ +/* $NetBSD: fsm.c,v 1.14 2013/07/20 05:16:08 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -112,6 +112,7 @@ run_ldp_hello(const struct ldp_pdu * pdu hi-ldp_id.s_addr = pduid-ldp_id.s_addr; memcpy(hi-transport_address, traddr, traddr.sa.sa_len); SLIST_INSERT_HEAD(hello_info_head, hi, infos); + may_connect = false; } /* Update expire timer */ @@ -236,5 +237,6 @@ set_my_ldp_id() freeifaddrs(ifa); debugp(LDP ID: %s\n, inet_ntoa(a)); strlcpy(my_ldp_id, inet_ntoa(a), INET_ADDRSTRLEN); + setproctitle(LDP ID: %s, my_ldp_id); return LDP_E_OK; } Index: src/usr.sbin/ldpd/ldp_peer.c diff -u src/usr.sbin/ldpd/ldp_peer.c:1.14 src/usr.sbin/ldpd/ldp_peer.c:1.15 --- src/usr.sbin/ldpd/ldp_peer.c:1.14 Thu Jul 18 06:07:45 2013 +++ src/usr.sbin/ldpd/ldp_peer.c Sat Jul 20 05:16:08 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: ldp_peer.c,v 1.14 2013/07/18 06:07:45 kefren Exp $ */ +/* $NetBSD: ldp_peer.c,v 1.15 2013/07/20 05:16:08 kefren Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -38,6 +38,7 @@ #include assert.h #include errno.h +#include fcntl.h #include stdlib.h #include strings.h #include stdio.h @@ -77,12 +78,11 @@ ldp_peer_new(const struct in_addr * ldp_ const struct sockaddr * tradd, uint16_t holdtime, int soc) { struct ldp_peer *p; - int s = soc; - struct sockaddr *connecting_sa = NULL; + int s = soc, sopts; + union sockunion connecting_su; struct conf_neighbour *cn; - if (tradd != NULL) - assert(tradd-sa_family == padd-sa_family); + assert(tradd == NULL || tradd-sa_family == padd-sa_family); if (soc 1) { s = socket(PF_INET, SOCK_STREAM, 0); @@ -91,22 +91,20 @@ ldp_peer_new(const struct in_addr * ldp_ return NULL; } if (tradd != NULL) { - connecting_sa = malloc(tradd-sa_len); - memcpy(connecting_sa, tradd, tradd-sa_len); + assert(tradd-sa_len = sizeof(connecting_su)); + memcpy(connecting_su, tradd, tradd-sa_len); } else { - connecting_sa = malloc(padd-sa_len); - memcpy(connecting_sa, padd, padd-sa_len); + assert(padd-sa_len = sizeof(connecting_su)); + memcpy(connecting_su, padd, padd-sa_len); } - assert(connecting_sa-sa_family == AF_INET || - connecting_sa-sa_family == AF_INET6); + assert(connecting_su.sa.sa_family == AF_INET || + connecting_su.sa.sa_family == AF_INET6); - if (connecting_sa-sa_family == AF_INET) - ((struct sockaddr_in*)connecting_sa)-sin_port = - htons(LDP_PORT); + if (connecting_su.sa.sa_family == AF_INET) + connecting_su.sin.sin_port = htons(LDP_PORT); else - ((struct sockaddr_in6*)connecting_sa)-sin6_port = - htons(LDP_PORT); + connecting_su.sin6.sin6_port = htons(LDP_PORT); set_ttl(s); } @@ -155,20 +153,23 @@ ldp_peer_new(const struct in_addr * ldp_ SLIST_INIT(p-label_mapping_head); p-timeout = p-holdtime; + sopts = fcntl(p-socket, F_GETFL); + if (sopts = 0) { + sopts |= O_NONBLOCK; + fcntl(p-socket, F_SETFL, sopts); + } + /* And connect to peer */ - if (soc 1) - if (connect(s, connecting_sa, connecting_sa-sa_len) == -1) { - if (errno == EINTR) { -free(connecting_sa); -return p; /* We take care of this in - * big_loop */ - } - warnp(connect to %s failed: %s\n, - satos(connecting_sa), strerror(errno)); - free(connecting_sa); - ldp_peer_holddown(p); - return NULL; - } + if (soc 1 + connect(s, connecting_su.sa, connecting_su.sa.sa_len) == -1) { + if (errno == EINTR || errno == EINPROGRESS) + /* We take care of this in big_loop */ + return p; + warnp(connect to %s failed: %s\n, + satos(connecting_su.sa), strerror(errno)); +
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Thu Jul 18 06:07:45 UTC 2013 Modified Files: src/usr.sbin/ldpd: label.c label.h ldp_command.c ldp_command.h ldp_peer.c mpls_interface.c mpls_interface.h mpls_routes.c socketops.c tlv_stack.c Log Message: Make sure labels are always updated when a route is added and when a peer is added Rework mpls_add_label according to that so no route refresh is done anymore Use poll when reading the PF_ROUTE socket setsockopt SO_USELOOPBACK on the PF_ROUTE socket Output some information on SIGINFO Allow map changing for a ldp peer Finally fix the connected routes admission into labels Correct the route trigger when a label map is received To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/ldpd/label.c cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/ldpd/label.h cvs rdiff -u -r1.11 -r1.12 src/usr.sbin/ldpd/ldp_command.c cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/ldpd/ldp_command.h cvs rdiff -u -r1.13 -r1.14 src/usr.sbin/ldpd/ldp_peer.c cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/ldpd/mpls_interface.c \ src/usr.sbin/ldpd/tlv_stack.c cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/ldpd/mpls_interface.h cvs rdiff -u -r1.16 -r1.17 src/usr.sbin/ldpd/mpls_routes.c cvs rdiff -u -r1.28 -r1.29 src/usr.sbin/ldpd/socketops.c 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/label.c diff -u src/usr.sbin/ldpd/label.c:1.7 src/usr.sbin/ldpd/label.c:1.8 --- src/usr.sbin/ldpd/label.c:1.7 Tue Jul 16 02:54:32 2013 +++ src/usr.sbin/ldpd/label.c Thu Jul 18 06:07:45 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: label.c,v 1.7 2013/07/16 02:54:32 kefren Exp $ */ +/* $NetBSD: label.c,v 1.8 2013/07/18 06:07:45 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -70,12 +70,13 @@ label_add(const union sockunion * so_des assert(so_dest); assert(so_pref); assert(so_dest-sa.sa_family == so_pref-sa.sa_family); + assert(label_get(so_dest, so_pref) == NULL); - memcpy(l-so_dest, so_dest, sizeof(union sockunion)); - memcpy(l-so_pref, so_pref, sizeof(union sockunion)); + memcpy(l-so_dest, so_dest, so_dest-sa.sa_len); + memcpy(l-so_pref, so_pref, so_pref-sa.sa_len); if (so_gate) - memcpy(l-so_gate, so_gate, sizeof(union sockunion)); + memcpy(l-so_gate, so_gate, so_gate-sa.sa_len); if (binding) l-binding = binding; else @@ -130,8 +131,8 @@ label_reattach_route(struct label *l, in /* Delete and re-add IPv4 route */ if (get_route(rg, l-so_dest, l-so_pref, 1) == LDP_E_OK) { delete_route(l-so_dest, l-so_pref, NO_FREESO); - add_route(l-so_dest, l-so_pref, l-so_gate, NULL, NULL, - NO_FREESO, RTM_READD); + add_route(l-so_dest, l-so_pref, l-so_gate, NULL, + NULL, NO_FREESO, RTM_READD); } else if (from_union_to_cidr(l-so_pref) == 32 l-so_dest.sa.sa_family == AF_INET get_route(rg, l-so_dest, NULL, 1) == LDP_E_OK) { @@ -225,15 +226,15 @@ label_del_by_binding(uint32_t binding, i struct label* label_get_by_prefix(const struct sockaddr *a, int prefixlen) { - union sockunion *so_dest, *so_pref; + const union sockunion *so_dest; + union sockunion *so_pref; struct label *l; - so_dest = make_inet_union(satos(a)); // XXX: grobian + so_dest = (const union sockunion *)a; so_pref = from_cidr_to_union(prefixlen); l = label_get(so_dest, so_pref); - free(so_dest); free(so_pref); return l; @@ -271,3 +272,20 @@ change_local_label(struct label *l, uint from_union_to_cidr((l-so_pref)), l-binding); } + +void +label_check_assoc(struct ldp_peer *p) +{ + struct label *l; + struct ldp_peer_address *wp; + + SLIST_FOREACH (l, label_head, labels) + if (l-p == NULL l-so_gate.sa.sa_family != 0) + SLIST_FOREACH(wp, p-ldp_peer_address_head, addresses) +if (sockaddr_cmp(l-so_gate.sa, +wp-address.sa) == 0){ + l-p = p; + l-label = MPLS_LABEL_IMPLNULL; + break; +} +} Index: src/usr.sbin/ldpd/label.h diff -u src/usr.sbin/ldpd/label.h:1.4 src/usr.sbin/ldpd/label.h:1.5 --- src/usr.sbin/ldpd/label.h:1.4 Thu Jul 11 10:46:19 2013 +++ src/usr.sbin/ldpd/label.h Thu Jul 18 06:07:45 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: label.h,v 1.4 2013/07/11 10:46:19 kefren Exp $ */ +/* $NetBSD: label.h,v 1.5 2013/07/18 06:07:45 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -69,5 +69,6 @@ struct label * label_get_by_prefix(const uint32_t get_free_local_label(void); void change_local_label(struct label*, uint32_t); void label_reattach_route(struct label*, int); +void label_check_assoc(struct ldp_peer *p); #endif /* !_LABEL_H_ */ Index: src/usr.sbin/ldpd/ldp_command.c diff -u src/usr.sbin/ldpd/ldp_command.c:1.11 src/usr.sbin/ldpd/ldp_command.c:1.12 --- src/usr.sbin/ldpd/ldp_command.c:1.11 Tue Jul 16 02:54:32 2013 +++ src/usr.sbin/ldpd/ldp_command.c Thu Jul 18 06:07:45 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: ldp_command.c,v 1.11 2013/07/16 02:54:32 kefren Exp $ */ +/*
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Thu Jul 18 11:45:36 UTC 2013 Modified Files: src/usr.sbin/ldpd: label.c label.h mpls_interface.c mpls_routes.c mpls_routes.h tlv_stack.c Log Message: * rework the reattachment code * build an implnull label when a route is added and let mpls_add_label to take care of relabelling * take out last piece of the code where we do route lookups - we should have every information we need in labels * tested these changes using a number of rump kernels and some couple of thousands of flapping routes To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/usr.sbin/ldpd/label.c cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/ldpd/label.h \ src/usr.sbin/ldpd/mpls_routes.h cvs rdiff -u -r1.10 -r1.11 src/usr.sbin/ldpd/mpls_interface.c \ src/usr.sbin/ldpd/tlv_stack.c cvs rdiff -u -r1.17 -r1.18 src/usr.sbin/ldpd/mpls_routes.c 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/label.c diff -u src/usr.sbin/ldpd/label.c:1.8 src/usr.sbin/ldpd/label.c:1.9 --- src/usr.sbin/ldpd/label.c:1.8 Thu Jul 18 06:07:45 2013 +++ src/usr.sbin/ldpd/label.c Thu Jul 18 11:45:36 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: label.c,v 1.8 2013/07/18 06:07:45 kefren Exp $ */ +/* $NetBSD: label.c,v 1.9 2013/07/18 11:45:36 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -106,53 +106,39 @@ label_del(struct label * l) } /* - * Delete or Reuse the old IPv4 route, delete MPLS route (if any) + * Delete or Reuse the old IPv4 route, delete MPLS route + * readd = REATT_INET_CHANGE - delete and recreate the INET route + * readd = REATT_INET_DEL - deletes INET route + * readd = REATT_INET_NODEL - doesn't touch the INET route */ void label_reattach_route(struct label *l, int readd) { - union sockunion *u; - union sockunion emptysu; - struct rt_msg rg; - int oldbinding = l-binding; warnp([label_reattach_route] binding %d deleted\n, l-binding); - l-p = NULL; - l-binding = MPLS_LABEL_IMPLNULL; - /* No gateway ? */ - memset(emptysu, 0, sizeof (union sockunion)); - if (memcmp(l-so_gate, emptysu, sizeof(union sockunion)) == 0) + if (l-so_gate.sa.sa_len == 0) return; - if (l-label != MPLS_LABEL_IMPLNULL readd == LDP_READD_CHANGE) { - /* Delete and re-add IPv4 route */ - if (get_route(rg, l-so_dest, l-so_pref, 1) == LDP_E_OK) { - delete_route(l-so_dest, l-so_pref, NO_FREESO); - add_route(l-so_dest, l-so_pref, l-so_gate, NULL, - NULL, NO_FREESO, RTM_READD); - } else if (from_union_to_cidr(l-so_pref) == 32 - l-so_dest.sa.sa_family == AF_INET - get_route(rg, l-so_dest, NULL, 1) == LDP_E_OK) { - delete_route(l-so_dest, NULL, NO_FREESO); - add_route(l-so_dest, NULL, l-so_gate, NULL, NULL, - NO_FREESO, RTM_READD); - } else - add_route(l-so_dest, l-so_pref, - l-so_gate, NULL, NULL, NO_FREESO, RTM_READD); - } else - if (readd != LDP_READD_NODEL) - delete_route(l-so_dest, l-so_pref, NO_FREESO); + if (readd == REATT_INET_CHANGE) { + /* Delete the tagged route and re-add IPv4 route */ + delete_route(l-so_dest, + l-so_pref.sa.sa_len != 0 ? l-so_pref : NULL, NO_FREESO); + add_route(l-so_dest, + l-so_pref.sa.sa_len != 0 ? l-so_pref : NULL, l-so_gate, + NULL, NULL, NO_FREESO, RTM_READD); + } else if (readd == REATT_INET_DEL) + delete_route(l-so_dest, l-so_pref, NO_FREESO); + + /* Deletes the MPLS route */ + if (l-binding = min_label) + delete_route(make_mpls_union(l-binding), NULL, FREESO); + l-binding = MPLS_LABEL_IMPLNULL; + l-p = NULL; l-label = 0; - - /* Deletes pure MPLS route */ - if (oldbinding = min_label) { - u = make_mpls_union(oldbinding); - delete_route(u, NULL, FREESO); - } } /* * Get a label by dst and pref @@ -260,14 +246,14 @@ get_free_local_label() } /* - * Change local binding + * Announce peers that a label has changed its binding + * by withdrawing it and reannouncing it */ void -change_local_label(struct label *l, uint32_t newbind) +announce_label_change(struct label *l) { send_withdraw_tlv_to_all((l-so_dest.sa), from_union_to_cidr((l-so_pref))); - l-binding = newbind; send_label_tlv_to_all((l-so_dest.sa), from_union_to_cidr((l-so_pref)), l-binding); Index: src/usr.sbin/ldpd/label.h diff -u src/usr.sbin/ldpd/label.h:1.5 src/usr.sbin/ldpd/label.h:1.6 --- src/usr.sbin/ldpd/label.h:1.5 Thu Jul 18 06:07:45 2013 +++ src/usr.sbin/ldpd/label.h Thu Jul 18 11:45:36 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: label.h,v 1.5 2013/07/18 06:07:45 kefren Exp $ */ +/* $NetBSD: label.h,v 1.6 2013/07/18 11:45:36 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -37,9 +37,9 @@ #include mpls_routes.h #include ldp_peer.h -#define LDP_READD_NODEL 0 -#define LDP_READD_CHANGE 1 -#define LDP_READD_NOCHANGE 2 +#define REATT_INET_CHANGE 0 +#define REATT_INET_DEL 1 +#define REATT_INET_NODEL 2 /* * MPLS label descriptor @@
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Tue Jul 16 16:55:01 UTC 2013 Modified Files: src/usr.sbin/ldpd: mpls_routes.c Log Message: create binding for connected routes on startup decay an warning message to debug only To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/usr.sbin/ldpd/mpls_routes.c 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/mpls_routes.c diff -u src/usr.sbin/ldpd/mpls_routes.c:1.15 src/usr.sbin/ldpd/mpls_routes.c:1.16 --- src/usr.sbin/ldpd/mpls_routes.c:1.15 Tue Jul 16 02:54:32 2013 +++ src/usr.sbin/ldpd/mpls_routes.c Tue Jul 16 16:55:01 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: mpls_routes.c,v 1.15 2013/07/16 02:54:32 kefren Exp $ */ +/* $NetBSD: mpls_routes.c,v 1.16 2013/07/16 16:55:01 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -726,7 +726,7 @@ check_route(struct rt_msg * rg, uint rle rg-m_rtm.rtm_type); } - warnp([check_route] Route %s: %s / %s - %s by PID:%d\n, oper, dest, + debugp([check_route] Route %s: %s / %s - %s by PID:%d\n, oper, dest, pref, gate, rg-m_rtm.rtm_pid); if(so_pref_allocated) @@ -879,7 +879,7 @@ bind_current_routes() free(so_pref); continue; } - if (so_gate-sa.sa_family == AF_INET) + if (so_gate == NULL || so_gate-sa.sa_family == AF_INET) label_add(so_dst, so_pref, so_gate, MPLS_LABEL_IMPLNULL, NULL, 0);
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Tue Jul 16 19:40:01 UTC 2013 Modified Files: src/usr.sbin/ldpd: tlv_stack.c Log Message: send the actual prefix on the wire instead of struct headers statify To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/usr.sbin/ldpd/tlv_stack.c 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/tlv_stack.c diff -u src/usr.sbin/ldpd/tlv_stack.c:1.8 src/usr.sbin/ldpd/tlv_stack.c:1.9 --- src/usr.sbin/ldpd/tlv_stack.c:1.8 Thu Jul 11 10:46:19 2013 +++ src/usr.sbin/ldpd/tlv_stack.c Tue Jul 16 19:40:01 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: tlv_stack.c,v 1.8 2013/07/11 10:46:19 kefren Exp $ */ +/* $NetBSD: tlv_stack.c,v 1.9 2013/07/16 19:40:01 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -47,9 +47,9 @@ #include mpls_interface.h #include tlv_stack.h -uint8_t ldp_ceil8(int); +static uint8_t ldp_ceil8(int); -uint8_t +static uint8_t ldp_ceil8(int x) { if (x % 8 == 0) @@ -285,7 +285,8 @@ send_label_tlv(const struct ldp_peer * p p-type = FEC_PREFIX; p-af = htons(LDP_AF_INET); p-prelen = prefixlen; - memcpy(p-prefix, addr, ldp_ceil8(prefixlen)); + memcpy(p-prefix, ((const struct sockaddr_in*)addr)-sin_addr, + ldp_ceil8(prefixlen)); /* LABEL TLV */ l = (struct label_tlv *) ((unsigned char *) p +
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Tue Jul 16 02:54:33 UTC 2013 Modified Files: src/usr.sbin/ldpd: label.c ldp_command.c ldp_errors.c mpls_routes.c mpls_routes.h Log Message: retire union_ntoa, replace it with satos check for valid sizes on PF_ROUTE socket minor comment update To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/ldpd/label.c cvs rdiff -u -r1.10 -r1.11 src/usr.sbin/ldpd/ldp_command.c cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/ldpd/ldp_errors.c cvs rdiff -u -r1.14 -r1.15 src/usr.sbin/ldpd/mpls_routes.c cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/ldpd/mpls_routes.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/label.c diff -u src/usr.sbin/ldpd/label.c:1.6 src/usr.sbin/ldpd/label.c:1.7 --- src/usr.sbin/ldpd/label.c:1.6 Thu Jul 11 10:46:19 2013 +++ src/usr.sbin/ldpd/label.c Tue Jul 16 02:54:32 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: label.c,v 1.6 2013/07/11 10:46:19 kefren Exp $ */ +/* $NetBSD: label.c,v 1.7 2013/07/16 02:54:32 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -85,9 +85,9 @@ label_add(const union sockunion * so_des SLIST_INSERT_HEAD(label_head, l, labels); - strlcpy(spreftmp, union_ntoa(so_pref), INET_ADDRSTRLEN); + strlcpy(spreftmp, satos(so_pref-sa), INET_ADDRSTRLEN); warnp([label_add] added binding %d for %s/%s\n, l-binding, - union_ntoa(so_dest), spreftmp); + satos(so_dest-sa), spreftmp); send_label_tlv_to_all((so_dest-sa), from_union_to_cidr(so_pref), l-binding); @@ -99,7 +99,7 @@ void label_del(struct label * l) { warnp([label_del] deleted binding %d for %s\n, l-binding, - union_ntoa(l-so_dest)); + satos(l-so_dest.sa)); SLIST_REMOVE(label_head, l, label, labels); free(l); } Index: src/usr.sbin/ldpd/ldp_command.c diff -u src/usr.sbin/ldpd/ldp_command.c:1.10 src/usr.sbin/ldpd/ldp_command.c:1.11 --- src/usr.sbin/ldpd/ldp_command.c:1.10 Mon Jan 28 21:08:14 2013 +++ src/usr.sbin/ldpd/ldp_command.c Tue Jul 16 02:54:32 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: ldp_command.c,v 1.10 2013/01/28 21:08:14 kefren Exp $ */ +/* $NetBSD: ldp_command.c,v 1.11 2013/07/16 02:54:32 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -513,9 +513,9 @@ show_bindings(int s, char *recvspace) writestr(s, sendspace); SLIST_FOREACH (l, label_head, labels) { snprintf(sendspace, MAXSEND, %d\t\t%s/, l-binding, - union_ntoa(l-so_dest)); + satos(l-so_dest.sa)); writestr(s, sendspace); - snprintf(sendspace, MAXSEND, %s, union_ntoa(l-so_pref)); + snprintf(sendspace, MAXSEND, %s, satos(l-so_pref.sa)); writestr(s, sendspace); if (l-p) snprintf(sendspace, MAXSEND, \t%s:%d\n, Index: src/usr.sbin/ldpd/ldp_errors.c diff -u src/usr.sbin/ldpd/ldp_errors.c:1.3 src/usr.sbin/ldpd/ldp_errors.c:1.4 --- src/usr.sbin/ldpd/ldp_errors.c:1.3 Sat Jan 26 17:29:55 2013 +++ src/usr.sbin/ldpd/ldp_errors.c Tue Jul 16 02:54:32 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: ldp_errors.c,v 1.3 2013/01/26 17:29:55 kefren Exp $ */ +/* $NetBSD: ldp_errors.c,v 1.4 2013/07/16 02:54:32 kefren Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -30,10 +30,12 @@ */ #include arpa/inet.h +#include netmpls/mpls.h #include sys/stat.h #include fcntl.h #include stdio.h #include stdarg.h +#include string.h #include syslog.h #include unistd.h @@ -45,6 +47,7 @@ int debug_f = 0, warn_f = 0, syslog_f = static void do_syslog(int, const char*, va_list) __printflike(2, 0); static char satos_str[INET6_ADDRSTRLEN INET_ADDRSTRLEN ? INET6_ADDRSTRLEN : INET_ADDRSTRLEN]; +static char *mpls_ntoa(const struct sockaddr_mpls *smpls); void debugp(const char *fmt, ...) @@ -134,8 +137,33 @@ satos(const struct sockaddr *sa) return INET6 ERROR; break; } + case AF_LINK: + { + strlcpy(satos_str, + link_ntoa((const struct sockaddr_dl *)sa), + sizeof(satos_str)); + break; + } + case AF_MPLS: + { + strlcpy(satos_str, + mpls_ntoa((const struct sockaddr_mpls *)sa), + sizeof(satos_str)); + break; + } default: return UNKNOWN AF; } return satos_str; } + +static char * +mpls_ntoa(const struct sockaddr_mpls *smpls) +{ + static char ret[10]; + union mpls_shim ms2; + + ms2.s_addr = ntohl(smpls-smpls_addr.s_addr); + snprintf(ret, sizeof(ret), %d, ms2.shim.label); + return ret; +} Index: src/usr.sbin/ldpd/mpls_routes.c diff -u src/usr.sbin/ldpd/mpls_routes.c:1.14 src/usr.sbin/ldpd/mpls_routes.c:1.15 --- src/usr.sbin/ldpd/mpls_routes.c:1.14 Fri Jul 12 08:55:52 2013 +++ src/usr.sbin/ldpd/mpls_routes.c Tue Jul 16 02:54:32 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: mpls_routes.c,v 1.14 2013/07/12 08:55:52 kefren Exp $ */ +/* $NetBSD: mpls_routes.c,v 1.15 2013/07/16 02:54:32 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -68,7 +68,6 @@ int replay_index = 0; static int read_route_socket(char
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Fri Jul 12 08:55:52 UTC 2013 Modified Files: src/usr.sbin/ldpd: fsm.c mpls_routes.c Log Message: correct loopback address test correct addr add/del handling To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/usr.sbin/ldpd/fsm.c cvs rdiff -u -r1.13 -r1.14 src/usr.sbin/ldpd/mpls_routes.c 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.12 src/usr.sbin/ldpd/fsm.c:1.13 --- src/usr.sbin/ldpd/fsm.c:1.12 Thu Jul 11 05:55:13 2013 +++ src/usr.sbin/ldpd/fsm.c Fri Jul 12 08:55:52 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: fsm.c,v 1.12 2013/07/11 05:55:13 kefren Exp $ */ +/* $NetBSD: fsm.c,v 1.13 2013/07/12 08:55:52 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -186,10 +186,11 @@ build_address_list_tlv(void) ia = t-a_address; for (adrcount = 0, ifb = ifa; ifb; ifb = ifb-ifa_next) { if ((ifb-ifa_addr-sa_family != AF_INET) || - (!(ifb-ifa_flags IFF_UP)) || - (ifb-ifa_flags IFF_LOOPBACK)) + (!(ifb-ifa_flags IFF_UP))) continue; sa = (struct sockaddr_in *) ifb-ifa_addr; + if (ntohl(sa-sin_addr.s_addr) 24 == IN_LOOPBACKNET) + continue; memcpy(ia[adrcount], sa-sin_addr, sizeof(struct in_addr)); adrcount++; } Index: src/usr.sbin/ldpd/mpls_routes.c diff -u src/usr.sbin/ldpd/mpls_routes.c:1.13 src/usr.sbin/ldpd/mpls_routes.c:1.14 --- src/usr.sbin/ldpd/mpls_routes.c:1.13 Thu Jul 11 18:02:03 2013 +++ src/usr.sbin/ldpd/mpls_routes.c Fri Jul 12 08:55:52 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: mpls_routes.c,v 1.13 2013/07/11 18:02:03 kefren Exp $ */ +/* $NetBSD: mpls_routes.c,v 1.14 2013/07/12 08:55:52 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -69,18 +69,19 @@ static int read_route_socket(char *, int void mask_addr(union sockunion *); int compare_sockunion(const union sockunion *, const union sockunion *); char * mpls_ntoa(union mpls_shim); -static int check_if_addr_updown(struct rt_msg * rg); +static int check_if_addr_updown(struct rt_msg *, uint); extern struct sockaddr mplssockaddr; /* Many lines inspired or shamelessly stolen from sbin/route/route.c */ #define NEXTADDR(u) \ - do { l = RT_ROUNDUP(u-sa.sa_len); memcpy(cp, u, l); cp += l; } while(0); + do { l = RT_ROUNDUP(u-sa.sa_len); memcpy(cp, u, l); cp += l;} while(0); #define NEXTADDR2(u) \ do { l = RT_ROUNDUP(u.sa_len); memcpy(cp, u, l); cp += l; } while(0); #define GETNEXT(sunion) \ - (union sockunion *) ((char *) (sunion) + RT_ROUNDUP((sunion)-sa.sa_len)) + (union sockunion *) ((char *) (sunion) + \ + RT_ROUNDUP((sunion)-sa.sa_len)) static int read_route_socket(char *s, int max) @@ -581,13 +582,16 @@ check_route(struct rt_msg * rg, uint rle gate[0] = 0; pref[0] = 0; - if (rlen = sizeof(struct rt_msghdr) || - rg-m_rtm.rtm_version != RTM_VERSION) + if (rlen 3 || rg-m_rtm.rtm_version != RTM_VERSION) return LDP_E_ROUTE_ERROR; if (rg-m_rtm.rtm_type == RTM_NEWADDR || rg-m_rtm.rtm_type == RTM_DELADDR) - return check_if_addr_updown(rg); + return check_if_addr_updown(rg, rlen); + + if (rlen sizeof(struct rt_msghdr)) + return LDP_E_ROUTE_ERROR; + if (rg-m_rtm.rtm_pid == getpid() || ((rg-m_rtm.rtm_flags RTF_DONE) == 0)) return LDP_E_OK; @@ -719,6 +723,9 @@ check_route(struct rt_msg * rg, uint rle case RTM_LOSING: strlcpy(oper, losing, 20); break; + case RTM_REDIRECT: + strlcpy(oper, redirect, 20); + break; case RTM_NEWADDR: strlcpy(oper, new address, 20); break; @@ -726,7 +733,7 @@ check_route(struct rt_msg * rg, uint rle strlcpy(oper, del address, 20); break; default: - snprintf(oper, 50, unknown 0x%X operation, + snprintf(oper, sizeof(oper), unknown 0x%X operation, rg-m_rtm.rtm_type); } @@ -742,25 +749,29 @@ check_route(struct rt_msg * rg, uint rle * Checks NEWADDR and DELADDR messages and sends announcements accordingly */ static int -check_if_addr_updown(struct rt_msg * rg) +check_if_addr_updown(struct rt_msg * rg, uint rlen) { union sockunion *ifa, *netmask; struct ldp_peer *p; struct address_list_tlv al_tlv; + struct ifa_msghdr *msghdr = (struct ifa_msghdr *)rg-m_rtm; - if ((rg-m_rtm.rtm_addrs RTA_NETMASK) == 0 || - (rg-m_rtm.rtm_addrs RTA_IFA) == 0) + if (rlen sizeof(struct ifa_msghdr) || + (msghdr-ifam_addrs RTA_NETMASK) == 0 || + (msghdr-ifam_addrs RTA_IFA) == 0) return LDP_E_ROUTE_ERROR; - ifa = netmask = (union sockunion *) rg-m_space; + /* we should have RTA_NETMASK, RTA_IFP, RTA_IFA and RTA_BRD */ + ifa = netmask = (union sockunion *)(msghdr + 1); if (netmask-sa.sa_family != AF_INET) return LDP_E_OK; - if (rg-m_rtm.rtm_addrs RTA_IFP) - ifa = GETNEXT(netmask); + if (msghdr-ifam_addrs RTA_IFP) + ifa = GETNEXT(ifa); ifa = GETNEXT(ifa); - if (ifa-sa.sa_family != AF_INET) + if (ifa-sa.sa_family !=
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Thu Jul 11 09:11:35 UTC 2013 Modified Files: src/usr.sbin/ldpd: mpls_routes.c Log Message: speed up a little bit the string-prefixlen transforms To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/usr.sbin/ldpd/mpls_routes.c 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/mpls_routes.c diff -u src/usr.sbin/ldpd/mpls_routes.c:1.10 src/usr.sbin/ldpd/mpls_routes.c:1.11 --- src/usr.sbin/ldpd/mpls_routes.c:1.10 Sat Jan 26 17:29:55 2013 +++ src/usr.sbin/ldpd/mpls_routes.c Thu Jul 11 09:11:35 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: mpls_routes.c,v 1.10 2013/01/26 17:29:55 kefren Exp $ */ +/* $NetBSD: mpls_routes.c,v 1.11 2013/07/11 09:11:35 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -229,16 +229,13 @@ from_cidr_to_union(uint8_t prefixlen) uint8_t from_mask_to_cidr(char *mask) { - /* LoL (although I don't think about something faster right now) */ - charmtest[20]; - uint8_ti; - - for (i = 1; i 32; i++) { - from_cidr_to_mask(i, mtest); - if (!strcmp(mask, mtest)) - break; - } - return i; + struct in_addr addr; + uint8_t plen = 0; + + if (inet_aton(mask, addr) != 0) + for (; addr.s_addr; plen++) + addr.s_addr = addr.s_addr - 1; + return plen; } uint8_t @@ -258,23 +255,13 @@ from_union_to_cidr(union sockunion *so_p void from_cidr_to_mask(uint8_t prefixlen, char *mask) { - uint32_t a = 0, p = prefixlen; - if (prefixlen 32) { - strlcpy(mask, 255.255.255.255, 16); - return; - } - for (; p 0; p--) { - a = a (p - 1); - a += 1; - a = a (p - 1); - } - /* is this OK ? */ -#if _BYTE_ORDER == _LITTLE_ENDIAN - a = a (32 - prefixlen); -#endif + uint32_t a = 0; + uint8_t plen = prefixlen 32 ? prefixlen : 32; + if (plen != 0) + a = (0x (32 - plen)) (32 - plen); snprintf(mask, 16, %d.%d.%d.%d, a 24, (a 8) 24, - (a 16) 24, (a 24) 24); + (a 16) 24, (a 24) 24); } char *
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Thu Jul 11 10:46:19 UTC 2013 Modified Files: src/usr.sbin/ldpd: conffile.c conffile.h label.c label.h mpls_routes.c mpls_routes.h tlv_stack.c tlv_stack.h Log Message: sprinkle more const To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/ldpd/conffile.c \ src/usr.sbin/ldpd/label.c cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/ldpd/conffile.h cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/ldpd/label.h \ src/usr.sbin/ldpd/mpls_routes.h src/usr.sbin/ldpd/tlv_stack.h cvs rdiff -u -r1.11 -r1.12 src/usr.sbin/ldpd/mpls_routes.c cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/ldpd/tlv_stack.c 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/conffile.c diff -u src/usr.sbin/ldpd/conffile.c:1.5 src/usr.sbin/ldpd/conffile.c:1.6 --- src/usr.sbin/ldpd/conffile.c:1.5 Sat Jan 26 21:07:49 2013 +++ src/usr.sbin/ldpd/conffile.c Thu Jul 11 10:46:19 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: conffile.c,v 1.5 2013/01/26 21:07:49 kefren Exp $ */ +/* $NetBSD: conffile.c,v 1.6 2013/07/11 10:46:19 kefren Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -90,7 +90,7 @@ struct conf_func main_commands[] = { * Parses config file */ int -conf_parsefile(char *fname) +conf_parsefile(const char *fname) { int i; char buf[LINEMAXSIZE + 1]; Index: src/usr.sbin/ldpd/label.c diff -u src/usr.sbin/ldpd/label.c:1.5 src/usr.sbin/ldpd/label.c:1.6 --- src/usr.sbin/ldpd/label.c:1.5 Thu Jul 11 05:45:23 2013 +++ src/usr.sbin/ldpd/label.c Thu Jul 11 10:46:19 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: label.c,v 1.5 2013/07/11 05:45:23 kefren Exp $ */ +/* $NetBSD: label.c,v 1.6 2013/07/11 10:46:19 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -53,9 +53,9 @@ label_init() * if binding == 0 it receives a free one */ struct label * -label_add(union sockunion * so_dest, union sockunion * so_pref, - union sockunion * so_gate, uint32_t binding, struct ldp_peer * p, - uint32_t label) +label_add(const union sockunion * so_dest, const union sockunion * so_pref, + const union sockunion * so_gate, uint32_t binding, + const struct ldp_peer * p, uint32_t label) { struct label *l; char spreftmp[INET_ADDRSTRLEN]; @@ -157,7 +157,7 @@ label_reattach_route(struct label *l, in * Get a label by dst and pref */ struct label* -label_get(union sockunion *sodest, union sockunion *sopref) +label_get(const union sockunion *sodest, const union sockunion *sopref) { struct label *l; @@ -189,7 +189,7 @@ label_reattach_all_peer_labels(const str * and delete them */ void -del_all_peer_labels(struct ldp_peer * p, int readd) +del_all_peer_labels(const struct ldp_peer * p, int readd) { struct label *l, *lnext; Index: src/usr.sbin/ldpd/conffile.h diff -u src/usr.sbin/ldpd/conffile.h:1.2 src/usr.sbin/ldpd/conffile.h:1.3 --- src/usr.sbin/ldpd/conffile.h:1.2 Sat Jan 26 21:07:49 2013 +++ src/usr.sbin/ldpd/conffile.h Thu Jul 11 10:46:19 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: conffile.h,v 1.2 2013/01/26 21:07:49 kefren Exp $ */ +/* $NetBSD: conffile.h,v 1.3 2013/07/11 10:46:19 kefren Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -57,6 +57,6 @@ struct passive_if { }; SLIST_HEAD(,passive_if) passifs_head; -int conf_parsefile(char *fname); +int conf_parsefile(const char *fname); #endif Index: src/usr.sbin/ldpd/label.h diff -u src/usr.sbin/ldpd/label.h:1.3 src/usr.sbin/ldpd/label.h:1.4 --- src/usr.sbin/ldpd/label.h:1.3 Thu Jul 11 05:45:23 2013 +++ src/usr.sbin/ldpd/label.h Thu Jul 11 10:46:19 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: label.h,v 1.3 2013/07/11 05:45:23 kefren Exp $ */ +/* $NetBSD: label.h,v 1.4 2013/07/11 10:46:19 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -57,13 +57,14 @@ struct label { SLIST_HEAD(,label) label_head; voidlabel_init(void); -struct label * label_add(union sockunion *, union sockunion *, - union sockunion *, uint32_t, struct ldp_peer *, uint32_t); +struct label * label_add(const union sockunion *, const union sockunion *, + const union sockunion *, uint32_t, const struct ldp_peer *, uint32_t); voidlabel_del(struct label *); -voiddel_all_peer_labels(struct ldp_peer*, int); +voiddel_all_peer_labels(const struct ldp_peer*, int); void label_reattach_all_peer_labels(const struct ldp_peer*, int); voidlabel_del_by_binding(uint32_t, int); -struct label * label_get(union sockunion *sodest, union sockunion *sopref); +struct label * label_get(const union sockunion *sodest, + const union sockunion *sopref); struct label * label_get_by_prefix(const struct sockaddr *, int); uint32_t get_free_local_label(void); void change_local_label(struct label*, uint32_t); Index: src/usr.sbin/ldpd/mpls_routes.h diff -u src/usr.sbin/ldpd/mpls_routes.h:1.3 src/usr.sbin/ldpd/mpls_routes.h:1.4 ---
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Thu Jul 11 05:45:23 UTC 2013 Modified Files: src/usr.sbin/ldpd: fsm.c fsm.h label.c label.h ldp_peer.c ldp_peer.h mpls_interface.c mpls_interface.h notifications.c notifications.h pdu.c pdu.h socketops.c socketops.h tlv_stack.c tlv_stack.h Log Message: Constify a little bit To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/usr.sbin/ldpd/fsm.c cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/ldpd/fsm.h cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/ldpd/label.c \ src/usr.sbin/ldpd/ldp_peer.h src/usr.sbin/ldpd/pdu.c cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/ldpd/label.h \ src/usr.sbin/ldpd/mpls_interface.h src/usr.sbin/ldpd/notifications.c \ src/usr.sbin/ldpd/notifications.h src/usr.sbin/ldpd/pdu.h \ src/usr.sbin/ldpd/tlv_stack.h cvs rdiff -u -r1.11 -r1.12 src/usr.sbin/ldpd/ldp_peer.c cvs rdiff -u -r1.8 -r1.9 src/usr.sbin/ldpd/mpls_interface.c cvs rdiff -u -r1.27 -r1.28 src/usr.sbin/ldpd/socketops.c cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/ldpd/socketops.h cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/ldpd/tlv_stack.c 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.10 src/usr.sbin/ldpd/fsm.c:1.11 --- src/usr.sbin/ldpd/fsm.c:1.10 Tue Feb 5 13:02:33 2013 +++ src/usr.sbin/ldpd/fsm.c Thu Jul 11 05:45:23 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: fsm.c,v 1.10 2013/02/05 13:02:33 kefren Exp $ */ +/* $NetBSD: fsm.c,v 1.11 2013/07/11 05:45:23 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -49,13 +49,14 @@ charmy_ldp_id[20]; struct sockaddr mplssockaddr; -/* Processing a hello */ +/* Process a hello */ void -run_ldp_hello(struct ldp_pdu * pduid, struct hello_tlv * ht, -struct sockaddr * padd, struct in_addr * ladd, int mysock, bool may_connect) +run_ldp_hello(const struct ldp_pdu * pduid, const struct hello_tlv * ht, +const struct sockaddr * padd, const struct in_addr * ladd, int mysock, +bool may_connect) { struct ldp_peer *peer = NULL; - struct transport_address_tlv *trtlv; + const struct transport_address_tlv *trtlv; struct hello_info *hi = NULL; union sockunion traddr; @@ -68,19 +69,15 @@ run_ldp_hello(struct ldp_pdu * pduid, st if (ht-length = 4) /* Common hello parameters */ return; - ht-ch.type = ntohs(ht-ch.type); - ht-ch.length = ntohs(ht-ch.length); - ht-ch.holdtime = ntohs(ht-ch.holdtime); - ht-ch.res = ntohs(ht-ch.res); - debugp(Common hello Type: 0x%.4X Length: %.2d R:%d T:%d - Hold time: %d\n, ht-ch.type, ht-ch.length, - ht-ch.tr / 2, ht-ch.tr % 2, ht-ch.holdtime); + debugp(Common hello Type: 0x%.4X Length: %.2d + Hold time: %d\n, ntohs(ht-ch.type), ntohs(ht-ch.length), + ht-ch.holdtime); memset(traddr, 0, sizeof(traddr)); /* Check transport TLV */ if (pduid-length - PDU_PAYLOAD_LENGTH - sizeof(struct hello_tlv) = 8) { - trtlv = (struct transport_address_tlv *)(ht + 1); + trtlv = (const struct transport_address_tlv *)(ht + 1); if (trtlv-type == htons(TLV_IPV4_TRANSPORT)) { traddr.sin.sin_family = AF_INET; traddr.sin.sin_len = sizeof(struct sockaddr_in); @@ -119,9 +116,9 @@ run_ldp_hello(struct ldp_pdu * pduid, st /* Update expire timer */ if (ht-ch.holdtime != 0) - hi-keepalive = ht-ch.holdtime; + hi-keepalive = ntohs(ht-ch.holdtime); else { - if (ht-ch.res 15 == 0) + if (ntohs(ht-ch.res) 15 == 0) hi-keepalive = LDP_HELLO_KEEP; else hi-keepalive = LDP_THELLO_KEEP; @@ -138,7 +135,7 @@ run_ldp_hello(struct ldp_pdu * pduid, st ntohl(ladd-s_addr))) { peer = ldp_peer_new(pduid-ldp_id, padd, hi-transport_address.sa, -ht-ch.holdtime, 0); +ntohs(ht-ch.holdtime), 0); if (peer == NULL) return; if (peer-state == LDP_PEER_CONNECTED) Index: src/usr.sbin/ldpd/fsm.h diff -u src/usr.sbin/ldpd/fsm.h:1.3 src/usr.sbin/ldpd/fsm.h:1.4 --- src/usr.sbin/ldpd/fsm.h:1.3 Sun Feb 3 19:41:59 2013 +++ src/usr.sbin/ldpd/fsm.h Thu Jul 11 05:45:23 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: fsm.h,v 1.3 2013/02/03 19:41:59 kefren Exp $ */ +/* $NetBSD: fsm.h,v 1.4 2013/07/11 05:45:23 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -35,8 +35,8 @@ #include tlv.h #include pdu.h -void run_ldp_hello(struct ldp_pdu *, struct hello_tlv *, - struct sockaddr *, struct in_addr *, int, bool); +void run_ldp_hello(const struct ldp_pdu *, const struct hello_tlv *, + const struct sockaddr *, const struct in_addr *, int, bool); struct address_list_tlv * build_address_list_tlv(void); int set_my_ldp_id(void); Index: src/usr.sbin/ldpd/label.c diff -u src/usr.sbin/ldpd/label.c:1.4 src/usr.sbin/ldpd/label.c:1.5 --- src/usr.sbin/ldpd/label.c:1.4 Sat Jan 26 17:29:55 2013 +++ src/usr.sbin/ldpd/label.c Thu Jul 11 05:45:23 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: label.c,v 1.4 2013/01/26 17:29:55 kefren Exp $ */ +/* $NetBSD:
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Thu Jul 11 05:55:13 UTC 2013 Modified Files: src/usr.sbin/ldpd: fsm.c ldp_peer.c ldp_peer.h Log Message: Local addresses vector is not needed anymore To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/usr.sbin/ldpd/fsm.c cvs rdiff -u -r1.12 -r1.13 src/usr.sbin/ldpd/ldp_peer.c cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/ldpd/ldp_peer.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.11 src/usr.sbin/ldpd/fsm.c:1.12 --- src/usr.sbin/ldpd/fsm.c:1.11 Thu Jul 11 05:45:23 2013 +++ src/usr.sbin/ldpd/fsm.c Thu Jul 11 05:55:13 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: fsm.c,v 1.11 2013/07/11 05:45:23 kefren Exp $ */ +/* $NetBSD: fsm.c,v 1.12 2013/07/11 05:55:13 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -195,7 +195,6 @@ build_address_list_tlv(void) } freeifaddrs(ifa); - add_my_if_addrs(ia, adrcount); return t; } Index: src/usr.sbin/ldpd/ldp_peer.c diff -u src/usr.sbin/ldpd/ldp_peer.c:1.12 src/usr.sbin/ldpd/ldp_peer.c:1.13 --- src/usr.sbin/ldpd/ldp_peer.c:1.12 Thu Jul 11 05:45:23 2013 +++ src/usr.sbin/ldpd/ldp_peer.c Thu Jul 11 05:55:13 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: ldp_peer.c,v 1.12 2013/07/11 05:45:23 kefren Exp $ */ +/* $NetBSD: ldp_peer.c,v 1.13 2013/07/11 05:55:13 kefren Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -54,13 +54,10 @@ extern int ldp_holddown_time; -struct in_addr *myaddresses; - void ldp_peer_init(void) { SLIST_INIT(ldp_peer_head); - myaddresses = NULL; } int @@ -422,19 +419,6 @@ print_bounded_addresses(const struct ldp warnp(%s\n, abuf); } -void -add_my_if_addrs(struct in_addr * a, int count) -{ - myaddresses = calloc((count + 1), sizeof(*myaddresses)); - - if (!myaddresses) { - fatalp(add_my_if_addrs: malloc problem\n); - return; - } - memcpy(myaddresses, a, count * sizeof(struct in_addr)); - myaddresses[count].s_addr = 0; -} - /* Adds a label and a prefix to a specific peer */ int ldp_peer_add_mapping(struct ldp_peer * p, const struct sockaddr * a, Index: src/usr.sbin/ldpd/ldp_peer.h diff -u src/usr.sbin/ldpd/ldp_peer.h:1.5 src/usr.sbin/ldpd/ldp_peer.h:1.6 --- src/usr.sbin/ldpd/ldp_peer.h:1.5 Thu Jul 11 05:45:23 2013 +++ src/usr.sbin/ldpd/ldp_peer.h Thu Jul 11 05:55:13 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: ldp_peer.h,v 1.5 2013/07/11 05:45:23 kefren Exp $ */ +/* $NetBSD: ldp_peer.h,v 1.6 2013/07/11 05:55:13 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -103,7 +103,6 @@ struct ldp_peer_address * check_ifaddr(c void print_bounded_addresses(const struct ldp_peer *); void del_all_ifaddr(struct ldp_peer *); int del_ifaddresses(struct ldp_peer *, const struct al_tlv *); -void add_my_if_addrs(struct in_addr *, int); int ldp_peer_add_mapping(struct ldp_peer *, const struct sockaddr *, int, int); int ldp_peer_delete_mapping(struct ldp_peer *, const struct sockaddr *, int);
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Sun Jun 23 06:40:26 UTC 2013 Modified Files: src/usr.sbin/ldpd: mpls_interface.c Log Message: allow INET6 gateways, split some long lines To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/ldpd/mpls_interface.c 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/mpls_interface.c diff -u src/usr.sbin/ldpd/mpls_interface.c:1.7 src/usr.sbin/ldpd/mpls_interface.c:1.8 --- src/usr.sbin/ldpd/mpls_interface.c:1.7 Sat Jan 26 17:29:55 2013 +++ src/usr.sbin/ldpd/mpls_interface.c Sun Jun 23 06:40:26 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: mpls_interface.c,v 1.7 2013/01/26 17:29:55 kefren Exp $ */ +/* $NetBSD: mpls_interface.c,v 1.8 2013/06/23 06:40:26 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -133,8 +133,9 @@ mpls_add_label(struct ldp_peer * p, stru RT_ROUNDUP(so_oldifa-sa.sa_len)); } - if (so_gate-sa.sa_family != AF_INET) { - debugp(Failed at family check - only INET supoprted for now\n); + if (so_gate-sa.sa_family != AF_INET + so_gate-sa.sa_family != AF_INET6) { + debugp(mpls_add_label: so_gate is not IP or IPv6\n); return LDP_E_BAD_AF; } @@ -153,7 +154,7 @@ mpls_add_label(struct ldp_peer * p, stru if (lab-binding == MPLS_LABEL_IMPLNULL) { change_local_label(lab, get_free_local_label()); if (!lab-binding) { - fatalp(No more free labels !!!\n); + fatalp(Label pool depleted\n); return LDP_E_TOO_MANY_LABELS; } } @@ -181,16 +182,18 @@ mpls_add_label(struct ldp_peer * p, stru fatalp(Out of memory\n); return LDP_E_MEMORY; } - if (add_route(so_dest, NULL, so_nexthop, NULL, so_tag, FREESO, RTM_ADD) != LDP_E_OK) + if (add_route(so_dest, NULL, so_nexthop, NULL, so_tag, + FREESO, RTM_ADD) != LDP_E_OK) return LDP_E_ROUTE_ERROR; - /* Now, let's add tag to IPv4 route and point it to mpls interface */ + /* Now, let's add tag to IP route and point it to mpls interface */ if ((so_dest = make_inet_union(satos(addr))) == NULL) { // XXX: grobian fatalp(Out of memory\n); return LDP_E_MEMORY; } - /* if prefixlen == 32 check if it's inserted as host + /* + * if prefixlen == 32 check if it's inserted as host * and treat it as host. It may also be set as /32 prefix * (thanks mlelstv for heads-up about this) */ @@ -227,7 +230,8 @@ mpls_add_label(struct ldp_peer * p, stru memcpy(so_ifa, so_oldifa, so_oldifa-sa.sa_len); } else so_ifa = NULL; - if (add_route(so_dest, so_pref, so_nexthop, so_ifa, so_tag, FREESO, RTM_CHANGE) != LDP_E_OK) + if (add_route(so_dest, so_pref, so_nexthop, so_ifa, so_tag, + FREESO, RTM_CHANGE) != LDP_E_OK) return LDP_E_ROUTE_ERROR; debugp(Added %s/%d as label %d to peer %s\n, satos(addr), len,
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Wed May 8 08:57:46 UTC 2013 Modified Files: src/usr.sbin/ldpd: socketops.c Log Message: First send initialize and keep alive after that. Fixes inter-operability issues regarding session initialization. To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 src/usr.sbin/ldpd/socketops.c 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/socketops.c diff -u src/usr.sbin/ldpd/socketops.c:1.26 src/usr.sbin/ldpd/socketops.c:1.27 --- src/usr.sbin/ldpd/socketops.c:1.26 Mon Feb 4 20:28:24 2013 +++ src/usr.sbin/ldpd/socketops.c Wed May 8 08:57:45 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: socketops.c,v 1.26 2013/02/04 20:28:24 kefren Exp $ */ +/* $NetBSD: socketops.c,v 1.27 2013/05/08 08:57:45 kefren Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -1144,8 +1144,8 @@ recv_session_pdu(struct ldp_peer * p) } if (!p-master) { -keep_alive(p); send_initialize(p); +keep_alive(p); } else { p-state = LDP_PEER_ESTABLISHED; p-established_t = time(NULL);
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Tue Feb 5 13:02:33 UTC 2013 Modified Files: src/usr.sbin/ldpd: fsm.c Log Message: Stop confusing peer hello source with peer transport address To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/ldpd/fsm.c 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.9 src/usr.sbin/ldpd/fsm.c:1.10 --- src/usr.sbin/ldpd/fsm.c:1.9 Sun Feb 3 19:41:59 2013 +++ src/usr.sbin/ldpd/fsm.c Tue Feb 5 13:02:33 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: fsm.c,v 1.9 2013/02/03 19:41:59 kefren Exp $ */ +/* $NetBSD: fsm.c,v 1.10 2013/02/05 13:02:33 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -56,7 +56,8 @@ run_ldp_hello(struct ldp_pdu * pduid, st { struct ldp_peer *peer = NULL; struct transport_address_tlv *trtlv; - struct hello_info *hi; + struct hello_info *hi = NULL; + union sockunion traddr; if ((!pduid) || (!ht)) return; @@ -65,32 +66,58 @@ run_ldp_hello(struct ldp_pdu * pduid, st debugp(Hello: Type: 0x%.4X Length: %.2d ID: %.8X\n, ht-type, ht-length, ht-messageid); + if (ht-length = 4) /* Common hello parameters */ + return; + ht-ch.type = ntohs(ht-ch.type); + ht-ch.length = ntohs(ht-ch.length); + ht-ch.holdtime = ntohs(ht-ch.holdtime); + ht-ch.res = ntohs(ht-ch.res); + debugp(Common hello Type: 0x%.4X Length: %.2d R:%d T:%d + Hold time: %d\n, ht-ch.type, ht-ch.length, + ht-ch.tr / 2, ht-ch.tr % 2, ht-ch.holdtime); + + memset(traddr, 0, sizeof(traddr)); + /* Check transport TLV */ + if (pduid-length - PDU_PAYLOAD_LENGTH - + sizeof(struct hello_tlv) = 8) { + trtlv = (struct transport_address_tlv *)(ht + 1); + if (trtlv-type == htons(TLV_IPV4_TRANSPORT)) { + traddr.sin.sin_family = AF_INET; + traddr.sin.sin_len = sizeof(struct sockaddr_in); + memcpy(traddr.sin.sin_addr, + trtlv-address, sizeof(struct in_addr)); + } else if (trtlv-type == htons(TLV_IPV6_TRANSPORT)) { + traddr.sin6.sin6_family = AF_INET6; + traddr.sin6.sin6_len = sizeof(struct sockaddr_in6); + memcpy(traddr.sin6.sin6_addr, + trtlv-address, sizeof(struct in6_addr)); + } else + warnp(Unknown AF %x for transport address\n, + ntohs(trtlv-type)); + } else { + /* Use LDP ID as transport address */ + traddr.sin.sin_family = AF_INET; + traddr.sin.sin_len = sizeof(struct sockaddr_in); + memcpy(traddr.sin.sin_addr, + pduid-ldp_id, sizeof(struct in_addr)); + } /* Add it to hello list or just update timer */ SLIST_FOREACH(hi, hello_info_head, infos) - if (hi-ldp_id.s_addr == pduid-ldp_id.s_addr) + if (hi-ldp_id.s_addr == pduid-ldp_id.s_addr + sockaddr_cmp(hi-transport_address.sa, traddr.sa) == 0) break; if (hi == NULL) { - hi = malloc(sizeof(*hi)); + hi = calloc(1, sizeof(*hi)); if (!hi) { fatalp(Cannot alloc a hello info structure); return; } hi-ldp_id.s_addr = pduid-ldp_id.s_addr; - hi-transport_address.sa.sa_family = 0; + memcpy(hi-transport_address, traddr, traddr.sa.sa_len); SLIST_INSERT_HEAD(hello_info_head, hi, infos); - } else - /* Just update timer */ - hi-keepalive = LDP_HELLO_KEEP; + } - if (ht-length = 4) /* Common hello parameters */ - return; - ht-ch.type = ntohs(ht-ch.type); - ht-ch.length = ntohs(ht-ch.length); - ht-ch.holdtime = ntohs(ht-ch.holdtime); - ht-ch.res = ntohs(ht-ch.res); - debugp(Common hello Type: 0x%.4X Length: %.2d R:%d T:%d - Hold time: %d\n, ht-ch.type, ht-ch.length, - ht-ch.tr / 2, ht-ch.tr % 2, ht-ch.holdtime); + /* Update expire timer */ if (ht-ch.holdtime != 0) hi-keepalive = ht-ch.holdtime; else { @@ -99,44 +126,16 @@ run_ldp_hello(struct ldp_pdu * pduid, st else hi-keepalive = LDP_THELLO_KEEP; } + if (!get_ldp_peer_by_id(pduid-ldp_id)) { - /* Check transport TLV */ - if (pduid-length - PDU_PAYLOAD_LENGTH - - 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(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(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; - 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
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Mon Feb 4 09:52:43 UTC 2013 Modified Files: src/usr.sbin/ldpd: ldp_peer.c Log Message: correct the sockaddr compare modify a couple of debug messages To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/usr.sbin/ldpd/ldp_peer.c 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/ldp_peer.c diff -u src/usr.sbin/ldpd/ldp_peer.c:1.8 src/usr.sbin/ldpd/ldp_peer.c:1.9 --- src/usr.sbin/ldpd/ldp_peer.c:1.8 Mon Jan 28 21:35:34 2013 +++ src/usr.sbin/ldpd/ldp_peer.c Mon Feb 4 09:52:43 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: ldp_peer.c,v 1.8 2013/01/28 21:35:34 kefren Exp $ */ +/* $NetBSD: ldp_peer.c,v 1.9 2013/02/04 09:52:43 kefren Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -66,9 +66,9 @@ ldp_peer_init(void) static int sockaddr_cmp(const struct sockaddr *a, const struct sockaddr *b) { - if (a-sa_len != b-sa_len || a-sa_family == b-sa_family) + if (a-sa_len != b-sa_len || a-sa_family != b-sa_family) return -1; - return memcmp(a-sa_data, b-sa_data, a-sa_len); + return memcmp(a, b, a-sa_len); } /* * soc should be 1 if there is already a TCP socket for this else we'll @@ -521,13 +521,14 @@ ldp_test_mapping(struct sockaddr * a, in return NULL; } if (lpeer-state != LDP_PEER_ESTABLISHED) { - warnp(ldp_test_mapping: peer is down ?!\n); + fatalp(ldp_test_mapping: peer is down ?!\n); return NULL; } lm = ldp_peer_get_lm(lpeer, a, prefix); if (!lm) { - debugp(Cannot match that prefix to the specified peer\n); + debugp(Cannot match prefix %s/%d to the specified peer\n, + satos(a), prefix); return NULL; } rv = malloc(sizeof(*rv));
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Mon Feb 4 10:53:15 UTC 2013 Modified Files: src/usr.sbin/ldpd: ldpd.8 Log Message: Mention IPv6, operation mode and re-section a bit To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/ldpd/ldpd.8 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/ldpd.8 diff -u src/usr.sbin/ldpd/ldpd.8:1.7 src/usr.sbin/ldpd/ldpd.8:1.8 --- src/usr.sbin/ldpd/ldpd.8:1.7 Mon Nov 12 22:46:59 2012 +++ src/usr.sbin/ldpd/ldpd.8 Mon Feb 4 10:53:14 2013 @@ -1,4 +1,4 @@ -.\ $NetBSD: ldpd.8,v 1.7 2012/11/12 22:46:59 wiz Exp $ +.\ $NetBSD: ldpd.8,v 1.8 2013/02/04 10:53:14 kefren Exp $ .\ .\ Copyright (c) 2010 The NetBSD Foundation, Inc. .\ All rights reserved. @@ -24,7 +24,7 @@ .\ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\ POSSIBILITY OF SUCH DAMAGE. .\ -.Dd November 12, 2012 +.Dd February 4, 2013 .Dt LDPD 8 .Os .Sh NAME @@ -38,16 +38,13 @@ .Sh DESCRIPTION .Nm is a utility used to automatically distribute labels between two MPLS LSRs -almost conforming to RFC5036. -Right now some features requested by RFC5036 are not fully implemented. -For more information please consult the +conforming to RFC5036. +Currently some features described by RFC5036 are not fully implemented (see .Sx BUGS -section. -As a security measure you SHOULD filter the LDP well-known (646) -TCP and UDP ports using your favourite packet filter before starting -.Nm . -This is the current way used to filter neighbours and to protect the -system of external attacks like route injections. +section). +.Nm +supports peering with IPv6 LDP speakers and IPv6 labels exchange, conforming +to specifications in RFC5036 and draft-ietf-mpls-ldp-ipv6. .Pp .Nm logs information using the @@ -74,6 +71,9 @@ routes will be changed into tagged route will be populated. Any change in MPLS topology will also be announced to LDP neighbors. .Nm +uses currently Independent Control Mapping and Downstream Unsolicited mode +for Label Advertisment. +.Nm will listen on a route socket and compute the necessary changes in order to change untagged routes into tagged routes. This means that one may use one's favourite dynamic routing protocol @@ -104,6 +104,12 @@ Changes the TCP control port (default: 2 .It Fl W Enable output of warning messages. .El +.Sh SECURITY CONSIDERATIONS +As a security measure you SHOULD filter the LDP well-known (646) +TCP and UDP ports using your favourite packet filter before starting +.Nm . +This is the current way used to filter neighbours and to protect the +system of possible external attacks like route injections. .Sh SEE ALSO .Rs .%R RFC @@ -117,6 +123,12 @@ Enable output of warning messages. .%D January 2001 .%T LDP Applicability .Re +.Rs +.%R DRAFT +.%N draft-ietf-mpls-ldp-ipv6-07 +.%D June 2012 +.%T Updates to LDP for IPv6 +.Re .Sh HISTORY The .Nm @@ -124,4 +136,4 @@ command appeared in .Nx 6.0 . .Sh BUGS .Nm -supports only IPv4 and doesn't implement Path Vector and Hop Count TLVs. +doesn't implement Path Vector and Hop Count TLVs.
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: wiz Date: Mon Feb 4 11:02:32 UTC 2013 Modified Files: src/usr.sbin/ldpd: ldpd.8 Log Message: Grammar. Sort sections. To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/usr.sbin/ldpd/ldpd.8 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/ldpd.8 diff -u src/usr.sbin/ldpd/ldpd.8:1.8 src/usr.sbin/ldpd/ldpd.8:1.9 --- src/usr.sbin/ldpd/ldpd.8:1.8 Mon Feb 4 10:53:14 2013 +++ src/usr.sbin/ldpd/ldpd.8 Mon Feb 4 11:02:32 2013 @@ -1,4 +1,4 @@ -.\ $NetBSD: ldpd.8,v 1.8 2013/02/04 10:53:14 kefren Exp $ +.\ $NetBSD: ldpd.8,v 1.9 2013/02/04 11:02:32 wiz Exp $ .\ .\ Copyright (c) 2010 The NetBSD Foundation, Inc. .\ All rights reserved. @@ -104,12 +104,6 @@ Changes the TCP control port (default: 2 .It Fl W Enable output of warning messages. .El -.Sh SECURITY CONSIDERATIONS -As a security measure you SHOULD filter the LDP well-known (646) -TCP and UDP ports using your favourite packet filter before starting -.Nm . -This is the current way used to filter neighbours and to protect the -system of possible external attacks like route injections. .Sh SEE ALSO .Rs .%R RFC @@ -137,3 +131,9 @@ command appeared in .Sh BUGS .Nm doesn't implement Path Vector and Hop Count TLVs. +.Sh SECURITY CONSIDERATIONS +As a security measure you SHOULD filter the LDP well-known (646) +TCP and UDP ports using your favourite packet filter before starting +.Nm . +This is the current way used to filter neighbours and to protect the +system from possible external attacks like route injections.
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Mon Feb 4 17:14:32 UTC 2013 Modified Files: src/usr.sbin/ldpd: ldp_peer.c ldp_peer.h pdu.c socketops.c Log Message: * Don't assume INET in connection path * Lookup in hello list in order to get the correct LDP ID, instead of transport address * Improve an error message To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/ldpd/ldp_peer.c cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/ldpd/ldp_peer.h src/usr.sbin/ldpd/pdu.c cvs rdiff -u -r1.24 -r1.25 src/usr.sbin/ldpd/socketops.c 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/ldp_peer.c diff -u src/usr.sbin/ldpd/ldp_peer.c:1.9 src/usr.sbin/ldpd/ldp_peer.c:1.10 --- src/usr.sbin/ldpd/ldp_peer.c:1.9 Mon Feb 4 09:52:43 2013 +++ src/usr.sbin/ldpd/ldp_peer.c Mon Feb 4 17:14:31 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: ldp_peer.c,v 1.9 2013/02/04 09:52:43 kefren Exp $ */ +/* $NetBSD: ldp_peer.c,v 1.10 2013/02/04 17:14:31 kefren Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -63,7 +63,7 @@ ldp_peer_init(void) myaddresses = NULL; } -static int +int sockaddr_cmp(const struct sockaddr *a, const struct sockaddr *b) { if (a-sa_len != b-sa_len || a-sa_family != b-sa_family) Index: src/usr.sbin/ldpd/ldp_peer.h diff -u src/usr.sbin/ldpd/ldp_peer.h:1.3 src/usr.sbin/ldpd/ldp_peer.h:1.4 --- src/usr.sbin/ldpd/ldp_peer.h:1.3 Sat Jan 26 17:29:55 2013 +++ src/usr.sbin/ldpd/ldp_peer.h Mon Feb 4 17:14:31 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: ldp_peer.h,v 1.3 2013/01/26 17:29:55 kefren Exp $ */ +/* $NetBSD: ldp_peer.h,v 1.4 2013/02/04 17:14:31 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -86,6 +86,7 @@ struct peer_map { #define LDP_PEER_ESTABLISHED 2 #define LDP_PEER_HOLDDOWN 3 +int sockaddr_cmp(const struct sockaddr *, const struct sockaddr *); voidldp_peer_init(void); struct ldp_peer * ldp_peer_new(const struct in_addr *, struct sockaddr *, struct sockaddr *, uint16_t, int); Index: src/usr.sbin/ldpd/pdu.c diff -u src/usr.sbin/ldpd/pdu.c:1.3 src/usr.sbin/ldpd/pdu.c:1.4 --- src/usr.sbin/ldpd/pdu.c:1.3 Mon Jan 28 21:35:35 2013 +++ src/usr.sbin/ldpd/pdu.c Mon Feb 4 17:14:31 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: pdu.c,v 1.3 2013/01/28 21:35:35 kefren Exp $ */ +/* $NetBSD: pdu.c,v 1.4 2013/02/04 17:14:31 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -67,8 +67,9 @@ check_recv_pdu(struct ldp_peer * p, stru return LDP_E_BAD_LENGTH; if (p-ldp_id.s_addr != rpdu-ldp_id.s_addr) { - fatalp(Invalid LDP ID received from %s\n, - inet_ntoa(p-ldp_id)); + fatalp(Invalid LDP ID %s received from , + inet_ntoa(rpdu-ldp_id)); + fatalp(%s\n, inet_ntoa(p-ldp_id)); notiftlv = build_notification(0, NOTIF_FATAL | NOTIF_BAD_LDP_ID); send_tlv(p, (struct tlv *) notiftlv); Index: src/usr.sbin/ldpd/socketops.c diff -u src/usr.sbin/ldpd/socketops.c:1.24 src/usr.sbin/ldpd/socketops.c:1.25 --- src/usr.sbin/ldpd/socketops.c:1.24 Sun Feb 3 19:41:59 2013 +++ src/usr.sbin/ldpd/socketops.c Mon Feb 4 17:14:31 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: socketops.c,v 1.24 2013/02/03 19:41:59 kefren Exp $ */ +/* $NetBSD: socketops.c,v 1.25 2013/02/04 17:14:31 kefren Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -941,38 +941,67 @@ the_big_loop(void) void new_peer_connection() { - struct sockaddr_in sa, sin_me; + union sockunion peer_address, my_address; + struct in_addr *peer_ldp_id = NULL; + struct hello_info *hi; int s; - s = accept(ls, (struct sockaddr *) sa, - (socklen_t) { sizeof(struct sockaddr_in) } ); + s = accept(ls, peer_address.sa, + (socklen_t) { sizeof(union sockunion) } ); if (s 0) { fatalp(accept: %s, strerror(errno)); return; } - if (get_ldp_peer((const struct sockaddr *)sa) != NULL) { + if (get_ldp_peer(peer_address.sa) != NULL) { close(s); return; } - warnp(Accepted a connection from %s\n, inet_ntoa(sa.sin_addr)); + warnp(Accepted a connection from %s\n, satos(peer_address.sa)); - if (getsockname(s, (struct sockaddr *)sin_me, - (socklen_t) { sizeof(struct sockaddr_in) } )) { + if (getsockname(s, my_address.sa, + (socklen_t) { sizeof(union sockunion) } )) { fatalp(new_peer_connection(): cannot getsockname\n); close(s); return; } + if (peer_address.sa.sa_family == AF_INET) + peer_address.sin.sin_port = 0; + else if (peer_address.sa.sa_family == AF_INET6) + peer_address.sin6.sin6_port = 0; + else { + fatalp(Unknown peer address family\n); + close(s); + return; + } - if (ntohl(sa.sin_addr.s_addr) ntohl(sin_me.sin_addr.s_addr)) { + /* Verify if it should connect - XXX: no check for INET6 */ + if (peer_address.sa.sa_family == AF_INET + ntohl(peer_address.sin.sin_addr.s_addr) + ntohl(my_address.sin.sin_addr.s_addr)) { fatalp(Peer %s: connect from lower ID\n, -
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Mon Feb 4 20:28:24 UTC 2013 Modified Files: src/usr.sbin/ldpd: ldp_peer.c socketops.c Log Message: move code around a little bit in order to call get_ldp_peer correctly check also for transport_address in get_ldp_peer To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/usr.sbin/ldpd/ldp_peer.c cvs rdiff -u -r1.25 -r1.26 src/usr.sbin/ldpd/socketops.c 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/ldp_peer.c diff -u src/usr.sbin/ldpd/ldp_peer.c:1.10 src/usr.sbin/ldpd/ldp_peer.c:1.11 --- src/usr.sbin/ldpd/ldp_peer.c:1.10 Mon Feb 4 17:14:31 2013 +++ src/usr.sbin/ldpd/ldp_peer.c Mon Feb 4 20:28:24 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: ldp_peer.c,v 1.10 2013/02/04 17:14:31 kefren Exp $ */ +/* $NetBSD: ldp_peer.c,v 1.11 2013/02/04 20:28:24 kefren Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -66,7 +66,8 @@ ldp_peer_init(void) int sockaddr_cmp(const struct sockaddr *a, const struct sockaddr *b) { - if (a-sa_len != b-sa_len || a-sa_family != b-sa_family) + if (a == NULL || b == NULL || a-sa_len != b-sa_len || + a-sa_family != b-sa_family) return -1; return memcmp(a, b, a-sa_len); } @@ -226,9 +227,9 @@ get_ldp_peer(const struct sockaddr * a) (const void *) p-ldp_id, sizeof(struct in_addr)) == 0) return p; - if (sockaddr_cmp(a, p-address) == 0) - return p; - if (a-sa_family == AF_INET check_ifaddr(p,a)) + if (sockaddr_cmp(a, p-address) == 0 || + sockaddr_cmp(a, p-transport_address) == 0 || + check_ifaddr(p, a)) return p; } return NULL; Index: src/usr.sbin/ldpd/socketops.c diff -u src/usr.sbin/ldpd/socketops.c:1.25 src/usr.sbin/ldpd/socketops.c:1.26 --- src/usr.sbin/ldpd/socketops.c:1.25 Mon Feb 4 17:14:31 2013 +++ src/usr.sbin/ldpd/socketops.c Mon Feb 4 20:28:24 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: socketops.c,v 1.25 2013/02/04 17:14:31 kefren Exp $ */ +/* $NetBSD: socketops.c,v 1.26 2013/02/04 20:28:24 kefren Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -953,19 +953,13 @@ new_peer_connection() return; } - if (get_ldp_peer(peer_address.sa) != NULL) { - close(s); - return; - } - - warnp(Accepted a connection from %s\n, satos(peer_address.sa)); - if (getsockname(s, my_address.sa, (socklen_t) { sizeof(union sockunion) } )) { fatalp(new_peer_connection(): cannot getsockname\n); close(s); return; } + if (peer_address.sa.sa_family == AF_INET) peer_address.sin.sin_port = 0; else if (peer_address.sa.sa_family == AF_INET6) @@ -976,6 +970,14 @@ new_peer_connection() return; } + /* Already peered or in holddown ? */ + if (get_ldp_peer(peer_address.sa) != NULL) { + close(s); + return; + } + + warnp(Accepted a connection from %s\n, satos(peer_address.sa)); + /* Verify if it should connect - XXX: no check for INET6 */ if (peer_address.sa.sa_family == AF_INET ntohl(peer_address.sin.sin_addr.s_addr)
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Sun Feb 3 19:41:59 UTC 2013 Modified Files: src/usr.sbin/ldpd: fsm.c fsm.h socketops.c Log Message: Don't try to connect to peers before sending hellos To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/usr.sbin/ldpd/fsm.c cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/ldpd/fsm.h cvs rdiff -u -r1.23 -r1.24 src/usr.sbin/ldpd/socketops.c 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.8 src/usr.sbin/ldpd/fsm.c:1.9 --- src/usr.sbin/ldpd/fsm.c:1.8 Mon Jan 28 20:06:52 2013 +++ src/usr.sbin/ldpd/fsm.c Sun Feb 3 19:41:59 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: fsm.c,v 1.8 2013/01/28 20:06:52 kefren Exp $ */ +/* $NetBSD: fsm.c,v 1.9 2013/02/03 19:41:59 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -52,7 +52,7 @@ struct sockaddr mplssockaddr; /* Processing a hello */ void run_ldp_hello(struct ldp_pdu * pduid, struct hello_tlv * ht, -struct sockaddr * padd, struct in_addr * ladd, int mysock) +struct sockaddr * padd, struct in_addr * ladd, int mysock, bool may_connect) { struct ldp_peer *peer = NULL; struct transport_address_tlv *trtlv; @@ -133,7 +133,8 @@ run_ldp_hello(struct ldp_pdu * pduid, st * otherwise it is passive. */ /* XXX TODO: check for IPv6 too */ - if (hi-transport_address.sa.sa_family == AF_INET + if (may_connect == true + 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, Index: src/usr.sbin/ldpd/fsm.h diff -u src/usr.sbin/ldpd/fsm.h:1.2 src/usr.sbin/ldpd/fsm.h:1.3 --- src/usr.sbin/ldpd/fsm.h:1.2 Sat Jan 26 17:29:55 2013 +++ src/usr.sbin/ldpd/fsm.h Sun Feb 3 19:41:59 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: fsm.h,v 1.2 2013/01/26 17:29:55 kefren Exp $ */ +/* $NetBSD: fsm.h,v 1.3 2013/02/03 19:41:59 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -36,7 +36,7 @@ #include pdu.h void run_ldp_hello(struct ldp_pdu *, struct hello_tlv *, - struct sockaddr *, struct in_addr *, int); + struct sockaddr *, struct in_addr *, int, bool); struct address_list_tlv * build_address_list_tlv(void); int set_my_ldp_id(void); Index: src/usr.sbin/ldpd/socketops.c diff -u src/usr.sbin/ldpd/socketops.c:1.23 src/usr.sbin/ldpd/socketops.c:1.24 --- src/usr.sbin/ldpd/socketops.c:1.23 Mon Jan 28 21:35:35 2013 +++ src/usr.sbin/ldpd/socketops.c Sun Feb 3 19:41:59 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: socketops.c,v 1.23 2013/01/28 21:35:35 kefren Exp $ */ +/* $NetBSD: socketops.c,v 1.24 2013/02/03 19:41:59 kefren Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -75,6 +75,7 @@ int ldp_keepalive_time = LDP_KEEPALIVE_T int ldp_holddown_time = LDP_HOLDTIME; int no_default_route = 1; int loop_detection = 0; +bool may_connect; void recv_pdu(int); void send_hello_alarm(int); @@ -703,7 +704,7 @@ recv_pdu(int sock) /* Fill the TLV messages */ t = get_hello_tlv(recvspace + i, c - i); - run_ldp_hello(rpdu, t, sender.sa, local_addr, sock); + run_ldp_hello(rpdu, t, sender.sa, local_addr, sock, may_connect); } void @@ -714,6 +715,8 @@ send_hello_alarm(int unused) time_t t = time(NULL); int olderrno = errno; + if (may_connect == false) + may_connect = true; /* Send hellos */ if (!(t % ldp_hello_time)) send_hello(); @@ -798,6 +801,7 @@ the_big_loop(void) signal(SIGTERM, bail_out); /* Send first hellos in 5 seconds. Avoid No hello notifications */ + may_connect = false; alarm(5); route_socket = socket(PF_ROUTE, SOCK_RAW, AF_UNSPEC);
CVS commit: src/usr.sbin/ldpd
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, +
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Mon Jan 28 20:32:05 UTC 2013 Modified Files: src/usr.sbin/ldpd: socketops.c Log Message: permit notifications even if session not fully established To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/usr.sbin/ldpd/socketops.c 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/socketops.c diff -u src/usr.sbin/ldpd/socketops.c:1.21 src/usr.sbin/ldpd/socketops.c:1.22 --- src/usr.sbin/ldpd/socketops.c:1.21 Mon Jan 28 20:06:52 2013 +++ src/usr.sbin/ldpd/socketops.c Mon Jan 28 20:32:04 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: socketops.c,v 1.21 2013/01/28 20:06:52 kefren Exp $ */ +/* $NetBSD: socketops.c,v 1.22 2013/01/28 20:32:04 kefren Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -1072,7 +1072,8 @@ recv_session_pdu(struct ldp_peer * p) /* Should we get the message ? */ if (p-state != LDP_PEER_ESTABLISHED ntohs(ttmp-type) != LDP_INITIALIZE - ntohs(ttmp-type) != LDP_KEEPALIVE) + ntohs(ttmp-type) != LDP_KEEPALIVE + ntohs(ttmp-type) != LDP_NOTIFICATION) break; /* The big switch */ switch (ntohs(ttmp-type)) {
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Mon Jan 28 21:08:14 UTC 2013 Modified Files: src/usr.sbin/ldpd: ldp_command.c ldp_peer.c Log Message: Use satos instead of inet_ntop Fix an alloc problem To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/ldpd/ldp_command.c cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/ldpd/ldp_peer.c 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/ldp_command.c diff -u src/usr.sbin/ldpd/ldp_command.c:1.9 src/usr.sbin/ldpd/ldp_command.c:1.10 --- src/usr.sbin/ldpd/ldp_command.c:1.9 Mon Jan 28 20:06:52 2013 +++ src/usr.sbin/ldpd/ldp_command.c Mon Jan 28 21:08:14 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: ldp_command.c,v 1.9 2013/01/28 20:06:52 kefren Exp $ */ +/* $NetBSD: ldp_command.c,v 1.10 2013/01/28 21:08:14 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -411,21 +411,16 @@ show_neighbours(int s, char *recvspace) socklen_t sin_len = sizeof(struct sockaddr_in); int enc; socklen_t enclen = sizeof(enc); - char traddress[39], nhaddress[39]; SLIST_FOREACH(p, ldp_peer_head, peers) { snprintf(sendspace, MAXSEND, LDP peer: %s\n, inet_ntoa(p-ldp_id)); writestr(s, sendspace); - inet_ntop(p-transport_address-sa_family, - p-transport_address-sa_data, traddress, 39); snprintf(sendspace, MAXSEND, Transport address: %s\n, - traddress); + satos(p-transport_address)); writestr(s, sendspace); - inet_ntop(p-address-sa_family, p-address-sa_data, - nhaddress, 39); snprintf(sendspace, MAXSEND, Next-hop address: %s\n, - nhaddress); + satos(p-address)); writestr(s, sendspace); snprintf(sendspace, MAXSEND, State: %s\n, ldp_state_to_name(p-state)); @@ -513,7 +508,6 @@ static int show_bindings(int s, char *recvspace) { struct label *l; - char labelgw[39]; snprintf(sendspace, MAXSEND, Local label\tNetwork\t\t\t\tNexthop\n); writestr(s, sendspace); @@ -523,12 +517,10 @@ show_bindings(int s, char *recvspace) writestr(s, sendspace); snprintf(sendspace, MAXSEND, %s, union_ntoa(l-so_pref)); writestr(s, sendspace); - if (l-p) { - inet_ntop(l-p-address-sa_family, - l-p-address-sa_data, labelgw, 39); + if (l-p) snprintf(sendspace, MAXSEND, \t%s:%d\n, - labelgw, l-label); - } else + satos(l-p-address), l-label); + else snprintf(sendspace, MAXSEND, \n); writestr(s, sendspace); } Index: src/usr.sbin/ldpd/ldp_peer.c diff -u src/usr.sbin/ldpd/ldp_peer.c:1.6 src/usr.sbin/ldpd/ldp_peer.c:1.7 --- src/usr.sbin/ldpd/ldp_peer.c:1.6 Sun Jan 27 05:53:21 2013 +++ src/usr.sbin/ldpd/ldp_peer.c Mon Jan 28 21:08:14 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: ldp_peer.c,v 1.6 2013/01/27 05:53:21 kefren Exp $ */ +/* $NetBSD: ldp_peer.c,v 1.7 2013/01/28 21:08:14 kefren Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -131,13 +131,15 @@ ldp_peer_new(const struct in_addr * ldp_ SLIST_INSERT_HEAD(ldp_peer_head, p, peers); p-address = (struct sockaddr *)malloc(padd-sa_len); - p-transport_address = (struct sockaddr *)malloc(padd-sa_len); memcpy(p-address, padd, padd-sa_len); memcpy(p-ldp_id, ldp_id, sizeof(struct in_addr)); - if (tradd != NULL) + if (tradd != NULL) { + p-transport_address = (struct sockaddr *)malloc(tradd-sa_len); memcpy(p-transport_address, tradd, tradd-sa_len); - else + } else { + p-transport_address = (struct sockaddr *)malloc(padd-sa_len); memcpy(p-transport_address, padd, padd-sa_len); + } p-holdtime=holdtime ldp_holddown_time ? holdtime : ldp_holddown_time; p-socket = s; if (soc 1) { @@ -401,11 +403,10 @@ void print_bounded_addresses(struct ldp_peer * p) { struct ldp_peer_address *wp; - char abuf[512], peername[39]; + char abuf[512]; - inet_ntop(p-address-sa_family, p-address-sa_data, peername, 39); snprintf(abuf, sizeof(abuf), Addresses bounded to peer %s: , - peername); + satos(p-address)); SLIST_FOREACH(wp, p-ldp_peer_address_head, addresses) { strncat(abuf, satos(wp-address.sa), sizeof(abuf) -1);
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Mon Jan 28 21:35:35 UTC 2013 Modified Files: src/usr.sbin/ldpd: ldp_errors.h ldp_peer.c pdu.c socketops.c Log Message: Be a little more strict when sending notifications and checking PDU To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/ldpd/ldp_errors.h cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/ldpd/ldp_peer.c cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/ldpd/pdu.c cvs rdiff -u -r1.22 -r1.23 src/usr.sbin/ldpd/socketops.c 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/ldp_errors.h diff -u src/usr.sbin/ldpd/ldp_errors.h:1.4 src/usr.sbin/ldpd/ldp_errors.h:1.5 --- src/usr.sbin/ldpd/ldp_errors.h:1.4 Sat Jan 26 17:29:55 2013 +++ src/usr.sbin/ldpd/ldp_errors.h Mon Jan 28 21:35:34 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: ldp_errors.h,v 1.4 2013/01/26 17:29:55 kefren Exp $ */ +/* $NetBSD: ldp_errors.h,v 1.5 2013/01/28 21:35:34 kefren Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -48,6 +48,7 @@ #define LDP_E_TOO_MANY_LABELS 13 #define LDP_E_INVAL 14 #define LDP_E_TOO_MANY_FDS 15 +#define LDP_E_BAD_ID 16 #define LDP_E_GENERIC 255 void printtime(void); Index: src/usr.sbin/ldpd/ldp_peer.c diff -u src/usr.sbin/ldpd/ldp_peer.c:1.7 src/usr.sbin/ldpd/ldp_peer.c:1.8 --- src/usr.sbin/ldpd/ldp_peer.c:1.7 Mon Jan 28 21:08:14 2013 +++ src/usr.sbin/ldpd/ldp_peer.c Mon Jan 28 21:35:34 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: ldp_peer.c,v 1.7 2013/01/28 21:08:14 kefren Exp $ */ +/* $NetBSD: ldp_peer.c,v 1.8 2013/01/28 21:35:34 kefren Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -193,7 +193,8 @@ ldp_peer_holddown_all() SLIST_FOREACH(p, ldp_peer_head, peers) { if ((p-state == LDP_PEER_ESTABLISHED) || (p-state == LDP_PEER_CONNECTED)) - send_notification(p, get_message_id(), NOTIF_SHUTDOWN); + send_notification(p, get_message_id(), + NOTIF_FATAL | NOTIF_SHUTDOWN); ldp_peer_holddown(p); } } Index: src/usr.sbin/ldpd/pdu.c diff -u src/usr.sbin/ldpd/pdu.c:1.2 src/usr.sbin/ldpd/pdu.c:1.3 --- src/usr.sbin/ldpd/pdu.c:1.2 Sat Jan 26 17:29:55 2013 +++ src/usr.sbin/ldpd/pdu.c Mon Jan 28 21:35:35 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: pdu.c,v 1.2 2013/01/26 17:29:55 kefren Exp $ */ +/* $NetBSD: pdu.c,v 1.3 2013/01/28 21:35:35 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -66,12 +66,22 @@ check_recv_pdu(struct ldp_peer * p, stru if (c MIN_PDU_SIZE) return LDP_E_BAD_LENGTH; + if (p-ldp_id.s_addr != rpdu-ldp_id.s_addr) { + fatalp(Invalid LDP ID received from %s\n, + inet_ntoa(p-ldp_id)); + notiftlv = build_notification(0, + NOTIF_FATAL | NOTIF_BAD_LDP_ID); + send_tlv(p, (struct tlv *) notiftlv); + free(notiftlv); + return LDP_E_BAD_ID; + } /* Check PDU for right LDP version */ if (ntohs(rpdu-version) != LDP_VERSION) { fatalp(Invalid PDU version received from %s (%d)\n, satos(p-address), ntohs(rpdu-version)); - notiftlv = build_notification(0, NOTIF_BAD_LDP_VER); + notiftlv = build_notification(0, + NOTIF_FATAL | NOTIF_BAD_LDP_VER); send_tlv(p, (struct tlv *) notiftlv); free(notiftlv); return LDP_E_BAD_VERSION; @@ -81,7 +91,8 @@ check_recv_pdu(struct ldp_peer * p, stru fatalp(Invalid PDU length received from %s (announced %d, received %d)\n, satos(p-address), ntohs(rpdu-length), (int) (c - PDU_VER_LENGTH)); - notiftlv = build_notification(0, NOTIF_BAD_PDU_LEN); + notiftlv = build_notification(0, + NOTIF_FATAL | NOTIF_BAD_PDU_LEN); send_tlv(p, (struct tlv *) notiftlv); free(notiftlv); return LDP_E_BAD_LENGTH; Index: src/usr.sbin/ldpd/socketops.c diff -u src/usr.sbin/ldpd/socketops.c:1.22 src/usr.sbin/ldpd/socketops.c:1.23 --- src/usr.sbin/ldpd/socketops.c:1.22 Mon Jan 28 20:32:04 2013 +++ src/usr.sbin/ldpd/socketops.c Mon Jan 28 21:35:35 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: socketops.c,v 1.22 2013/01/28 20:32:04 kefren Exp $ */ +/* $NetBSD: socketops.c,v 1.23 2013/01/28 21:35:35 kefren Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -734,7 +734,7 @@ send_hello_alarm(int unused) case LDP_PEER_ESTABLISHED: case LDP_PEER_CONNECTED: send_notification(p, 0, -NOTIF_KEEP_ALIVE_TIMER_EXPIRED); +NOTIF_FATAL|NOTIF_KEEP_ALIVE_TIMER_EXPIRED); warnp(Keepalive expired for %s\n, inet_ntoa(p-ldp_id)); ldp_peer_holddown(p);
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Sat Jan 26 17:46:50 UTC 2013 Modified Files: src/usr.sbin/ldpd: socketops.c Log Message: allow compile without -DINET6 To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/usr.sbin/ldpd/socketops.c 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/socketops.c diff -u src/usr.sbin/ldpd/socketops.c:1.17 src/usr.sbin/ldpd/socketops.c:1.18 --- src/usr.sbin/ldpd/socketops.c:1.17 Sat Jan 26 17:29:55 2013 +++ src/usr.sbin/ldpd/socketops.c Sat Jan 26 17:46:50 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: socketops.c,v 1.17 2013/01/26 17:29:55 kefren Exp $ */ +/* $NetBSD: socketops.c,v 1.18 2013/01/26 17:46:50 kefren Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -89,10 +89,10 @@ create_hello_sockets() { struct ip_mreq mcast_addr; int s, joined_groups; -#ifdef INET6 - struct ipv6_mreq mcast_addr6; struct ifaddrs *ifa, *ifb; uint lastifindex; +#ifdef INET6 + struct ipv6_mreq mcast_addr6; struct sockaddr_in6 *if_sa6; #endif struct hello_socket *hs;
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Sat Jan 26 19:44:52 UTC 2013 Modified Files: src/usr.sbin/ldpd: ldp.h socketops.c Log Message: use predefined group consts/macros instead of ptoning strings To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/ldpd/ldp.h cvs rdiff -u -r1.18 -r1.19 src/usr.sbin/ldpd/socketops.c 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/ldp.h diff -u src/usr.sbin/ldpd/ldp.h:1.5 src/usr.sbin/ldpd/ldp.h:1.6 --- src/usr.sbin/ldpd/ldp.h:1.5 Sat Jan 26 17:29:55 2013 +++ src/usr.sbin/ldpd/ldp.h Sat Jan 26 19:44:52 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: ldp.h,v 1.5 2013/01/26 17:29:55 kefren Exp $ */ +/* $NetBSD: ldp.h,v 1.6 2013/01/26 19:44:52 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -36,10 +36,6 @@ #include netinet/in.h /* RFC5036 */ -#define ALL_ROUTERS 224.0.0.2 -/* draft-ietf-mpls-ldp-ipv6 */ -#define ALL_ROUTERS6 FF02::2 -/* RFC5036 */ #define LDP_PORT 646 #define LDP_COMMAND_PORT 2626 Index: src/usr.sbin/ldpd/socketops.c diff -u src/usr.sbin/ldpd/socketops.c:1.18 src/usr.sbin/ldpd/socketops.c:1.19 --- src/usr.sbin/ldpd/socketops.c:1.18 Sat Jan 26 17:46:50 2013 +++ src/usr.sbin/ldpd/socketops.c Sat Jan 26 19:44:52 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: socketops.c,v 1.18 2013/01/26 17:46:50 kefren Exp $ */ +/* $NetBSD: socketops.c,v 1.19 2013/01/26 19:44:52 kefren Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -107,7 +107,7 @@ create_hello_sockets() * RFC5036 specifies we should listen to all subnet routers multicast * group */ - assert(inet_pton(AF_INET, ALL_ROUTERS, mcast_addr.imr_multiaddr) == 1); + mcast_addr.imr_multiaddr.s_addr = htonl(INADDR_ALLRTRS_GROUP); if (socket_reuse_port(s) 0) goto chs_error; @@ -206,8 +206,7 @@ create_hello_sockets() } lastifindex = UINT_MAX; - assert(inet_pton(AF_INET6, ALL_ROUTERS6, - mcast_addr6.ipv6mr_multiaddr) == 1); + mcast_addr6.ipv6mr_multiaddr = in6addr_linklocal_allrouters; for (ifb = ifa; ifb; ifb = ifb-ifa_next) { if_sa6 = (struct sockaddr_in6 *) ifb-ifa_addr; if (if_sa6-sin6_family != AF_INET6 || @@ -452,7 +451,7 @@ send_hello(void) sadest.sin_len = sizeof(sadest); sadest.sin_family = AF_INET; sadest.sin_port = htons(LDP_PORT); - inet_aton(ALL_ROUTERS, sadest.sin_addr); + sadest.sin_addr.s_addr = htonl(INADDR_ALLRTRS_GROUP); /* Find our socket */ SLIST_FOREACH(hs, hello_socket_head, listentry) @@ -516,7 +515,7 @@ send_hello(void) sadest6.sin6_len = sizeof(sadest6); sadest6.sin6_family = AF_INET6; sadest6.sin6_port = htons(LDP_PORT); - assert(inet_pton(AF_INET6, ALL_ROUTERS6, sadest6.sin6_addr) == 1); + sadest6.sin6_addr = in6addr_linklocal_allrouters; SLIST_FOREACH(hs, hello_socket_head, listentry) if (hs-type == AF_INET6) {
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Sat Jan 26 21:07:49 UTC 2013 Modified Files: src/usr.sbin/ldpd: conffile.c conffile.h socketops.c Log Message: * add a new keyword for config file - passive-if and check if it's allowed to use the interface before join/send mcast * check if interface supports multicast before join/send mcast To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/ldpd/conffile.c cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/ldpd/conffile.h cvs rdiff -u -r1.19 -r1.20 src/usr.sbin/ldpd/socketops.c 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/conffile.c diff -u src/usr.sbin/ldpd/conffile.c:1.4 src/usr.sbin/ldpd/conffile.c:1.5 --- src/usr.sbin/ldpd/conffile.c:1.4 Mon Nov 12 18:39:00 2012 +++ src/usr.sbin/ldpd/conffile.c Sat Jan 26 21:07:49 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: conffile.c,v 1.4 2012/11/12 18:39:00 kefren Exp $ */ +/* $NetBSD: conffile.c,v 1.5 2013/01/26 21:07:49 kefren Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -63,6 +63,7 @@ static int Fneighbour(char*); static int Gneighbour(struct conf_neighbour *, char *); static int Fnodefault(char*); static int Floopdetection(char*); +static int Fpassiveif(char*); struct conf_func { char com[64]; @@ -81,6 +82,7 @@ struct conf_func main_commands[] = { { neighbour, Fneighbour }, { no-default-route, Fnodefault }, { loop-detection, Floopdetection }, + { passive-if, Fpassiveif }, { , NULL }, }; @@ -94,6 +96,7 @@ conf_parsefile(char *fname) char buf[LINEMAXSIZE + 1]; SLIST_INIT(conei_head); + SLIST_INIT(passifs_head); conf_ldp_id.s_addr = 0; confh = open(fname, O_RDONLY, 0); @@ -324,3 +327,16 @@ Floopdetection(char *line) loop_detection = loopd; return 0; } + +int +Fpassiveif(char *line) +{ + struct passive_if *pif; + + if (strlen(line) IF_NAMESIZE - 1) + return E_CONF_PARAM; + pif = calloc(1, sizeof(*pif)); + strlcpy(pif-if_name, line, IF_NAMESIZE); + SLIST_INSERT_HEAD(passifs_head, pif, listentry); + return 0; +} Index: src/usr.sbin/ldpd/conffile.h diff -u src/usr.sbin/ldpd/conffile.h:1.1 src/usr.sbin/ldpd/conffile.h:1.2 --- src/usr.sbin/ldpd/conffile.h:1.1 Thu Dec 30 11:29:21 2010 +++ src/usr.sbin/ldpd/conffile.h Sat Jan 26 21:07:49 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: conffile.h,v 1.1 2010/12/30 11:29:21 kefren Exp $ */ +/* $NetBSD: conffile.h,v 1.2 2013/01/26 21:07:49 kefren Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -32,6 +32,7 @@ #ifndef __CONFFILE_H #define __CONFFILE_H +#include net/if.h #include netinet/in.h #include sys/queue.h @@ -50,6 +51,11 @@ struct conf_neighbour { }; SLIST_HEAD(,conf_neighbour) conei_head; +struct passive_if { + char if_name[IF_NAMESIZE]; + SLIST_ENTRY(passive_if) listentry; +}; +SLIST_HEAD(,passive_if) passifs_head; int conf_parsefile(char *fname); Index: src/usr.sbin/ldpd/socketops.c diff -u src/usr.sbin/ldpd/socketops.c:1.19 src/usr.sbin/ldpd/socketops.c:1.20 --- src/usr.sbin/ldpd/socketops.c:1.19 Sat Jan 26 19:44:52 2013 +++ src/usr.sbin/ldpd/socketops.c Sat Jan 26 21:07:49 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: socketops.c,v 1.19 2013/01/26 19:44:52 kefren Exp $ */ +/* $NetBSD: socketops.c,v 1.20 2013/01/26 21:07:49 kefren Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -47,6 +47,7 @@ #include strings.h #include unistd.h +#include conffile.h #include fsm.h #include ldp.h #include ldp_command.h @@ -83,6 +84,7 @@ static int set_tos(int); static int socket_reuse_port(int); static int get_local_addr(struct sockaddr_dl *, struct in_addr *); static int is_hello_socket(int); +static int is_passive_if(char *if_name); int create_hello_sockets() @@ -134,7 +136,9 @@ create_hello_sockets() struct sockaddr_in *if_sa = (struct sockaddr_in *) ifb-ifa_addr; if (if_sa-sin_family != AF_INET || (!(ifb-ifa_flags IFF_UP)) || (ifb-ifa_flags IFF_LOOPBACK) || + (!(ifb-ifa_flags IFF_MULTICAST)) || (ntohl(if_sa-sin_addr.s_addr) 24 == IN_LOOPBACKNET) || + is_passive_if(ifb-ifa_name) || lastifindex == if_nametoindex(ifb-ifa_name)) continue; lastifindex = if_nametoindex(ifb-ifa_name); @@ -211,7 +215,9 @@ create_hello_sockets() if_sa6 = (struct sockaddr_in6 *) ifb-ifa_addr; if (if_sa6-sin6_family != AF_INET6 || (!(ifb-ifa_flags IFF_UP)) || + (!(ifb-ifa_flags IFF_MULTICAST)) || (ifb-ifa_flags IFF_LOOPBACK) || + is_passive_if(ifb-ifa_name) || IN6_IS_ADDR_LOOPBACK(if_sa6-sin6_addr)) continue; /* @@ -275,6 +281,18 @@ is_hello_socket(int s) return 0; } +/* Check if interface is passive */ +static int +is_passive_if(char *if_name) +{ + struct passive_if *pif; + + SLIST_FOREACH(pif, passifs_head, listentry) + if (strncasecmp(if_name, pif-if_name, IF_NAMESIZE) == 0) + return 1; + return 0; +} + /* Sets the TTL to 1 as we don't want to transmit outside
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Sun Jan 27 05:53:21 UTC 2013 Modified Files: src/usr.sbin/ldpd: ldp_peer.c Log Message: re-enable peer authentication To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/ldpd/ldp_peer.c 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/ldp_peer.c diff -u src/usr.sbin/ldpd/ldp_peer.c:1.5 src/usr.sbin/ldpd/ldp_peer.c:1.6 --- src/usr.sbin/ldpd/ldp_peer.c:1.5 Sat Jan 26 17:29:55 2013 +++ src/usr.sbin/ldpd/ldp_peer.c Sun Jan 27 05:53:21 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: ldp_peer.c,v 1.5 2013/01/26 17:29:55 kefren Exp $ */ +/* $NetBSD: ldp_peer.c,v 1.6 2013/01/27 05:53:21 kefren Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -81,9 +81,8 @@ ldp_peer_new(const struct in_addr * ldp_ struct ldp_peer *p; int s = soc; struct sockaddr *connecting_sa = NULL; - /* disabled - see below struct conf_neighbour *cn; - */ + if (tradd != NULL) assert(tradd-sa_family == padd-sa_family); @@ -112,17 +111,16 @@ ldp_peer_new(const struct in_addr * ldp_ } /* MD5 authentication needed ? */ -/* XXX: disabled for now - need to make sure NetBSD handles TCPSIG correctly SLIST_FOREACH(cn, conei_head, neilist) - if (cn-authenticate != 0 (a-s_addr == cn-address.s_addr || - (tradd tradd-s_addr == cn-address.s_addr))) { + if (cn-authenticate != 0 + ldp_id-s_addr == cn-address.s_addr) { if (setsockopt(s, IPPROTO_TCP, TCP_MD5SIG, (int){1}, sizeof(int)) != 0) fatalp(setsockopt TCP_MD5SIG: %s\n, strerror(errno)); break; } -*/ + /* Set the peer in CONNECTING/CONNECTED state */ p = calloc(1, sizeof(*p));
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Wed Jan 16 08:28:46 UTC 2013 Modified Files: src/usr.sbin/ldpd: mpls_routes.h socketops.c Log Message: Make sure there is enough space for sockaddr subtypes Use u_char for IP_MULTICAST_LOOP as specified in in.h To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/ldpd/mpls_routes.h cvs rdiff -u -r1.15 -r1.16 src/usr.sbin/ldpd/socketops.c 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/mpls_routes.h diff -u src/usr.sbin/ldpd/mpls_routes.h:1.1 src/usr.sbin/ldpd/mpls_routes.h:1.2 --- src/usr.sbin/ldpd/mpls_routes.h:1.1 Wed Dec 8 07:20:15 2010 +++ src/usr.sbin/ldpd/mpls_routes.h Wed Jan 16 08:28:44 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: mpls_routes.h,v 1.1 2010/12/08 07:20:15 kefren Exp $ */ +/* $NetBSD: mpls_routes.h,v 1.2 2013/01/16 08:28:44 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -49,6 +49,7 @@ union sockunion { struct sockaddr sa; struct sockaddr_in sin; + struct sockaddr_in6 sin6; struct sockaddr_mpls smpls; struct sockaddr_dl sdl; }; Index: src/usr.sbin/ldpd/socketops.c diff -u src/usr.sbin/ldpd/socketops.c:1.15 src/usr.sbin/ldpd/socketops.c:1.16 --- src/usr.sbin/ldpd/socketops.c:1.15 Tue Nov 13 06:58:58 2012 +++ src/usr.sbin/ldpd/socketops.c Wed Jan 16 08:28:45 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: socketops.c,v 1.15 2012/11/13 06:58:58 kefren Exp $ */ +/* $NetBSD: socketops.c,v 1.16 2013/01/16 08:28:45 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -147,8 +147,8 @@ create_hello_sockets() #endif /* We don't need to receive back our messages */ - if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, (uint8_t){0}, - sizeof(uint8_t)) == -1) { + if (setsockopt(s, IPPROTO_IP, IP_MULTICAST_LOOP, (u_char){0}, + sizeof(u_char)) == -1) { fatalp(INET setsockopt IP_MCAST_LOOP: %s\n, strerror(errno)); goto chs_error; } @@ -260,27 +260,25 @@ socket_reuse_port(int s) static int bind_socket(int s, uint8_t stype) { - struct sockaddr sa; + union sockunion su; assert (stype == 4 || stype == 6); if (stype == 4) { - struct sockaddr_in *sa_inet = (struct sockaddr_in *)(sa); - sa_inet-sin_len = sizeof(*sa_inet); - sa_inet-sin_family = AF_INET; - sa_inet-sin_addr.s_addr = INADDR_ANY; - sa_inet-sin_port = htons(LDP_PORT); + su.sin.sin_len = sizeof(su.sin); + su.sin.sin_family = AF_INET; + su.sin.sin_addr.s_addr = INADDR_ANY; + su.sin.sin_port = htons(LDP_PORT); } #ifdef INET6 else if (stype == 6) { - struct sockaddr_in6 *sa_inet6 = (struct sockaddr_in6 *)(sa); - sa_inet6-sin6_len = sizeof(*sa_inet6); - sa_inet6-sin6_family = AF_INET6; - sa_inet6-sin6_addr = in6addr_any; - sa_inet6-sin6_port = htons(LDP_PORT); + su.sin6.sin6_len = sizeof(su.sin6); + su.sin6.sin6_family = AF_INET6; + su.sin6.sin6_addr = in6addr_any; + su.sin6.sin6_port = htons(LDP_PORT); } #endif - if (bind(s, sa, sa.sa_len)) { + if (bind(s, su.sa, su.sa.sa_len)) { fatalp(bind_socket: %s\n, strerror(errno)); return -1; }
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Mon Nov 12 18:39:01 UTC 2012 Modified Files: src/usr.sbin/ldpd: Makefile conffile.c fsm.c ldp.h ldp_peer.c ldp_peer.h ldpd.8 main.c notifications.h socketops.c socketops.h tlv.h tlv_stack.c Log Message: * add initial IPv6 support - still incomplete at this moment, but it sends out there IPv6 hellos. Interoperability not yet tested. * sync man page with reality To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/ldpd/Makefile \ src/usr.sbin/ldpd/conffile.c src/usr.sbin/ldpd/ldp.h \ src/usr.sbin/ldpd/ldp_peer.c cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/ldpd/fsm.c src/usr.sbin/ldpd/ldpd.8 cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/ldpd/ldp_peer.h \ src/usr.sbin/ldpd/notifications.h src/usr.sbin/ldpd/tlv.h cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/ldpd/main.c cvs rdiff -u -r1.11 -r1.12 src/usr.sbin/ldpd/socketops.c cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/ldpd/socketops.h cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/ldpd/tlv_stack.c 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/Makefile diff -u src/usr.sbin/ldpd/Makefile:1.3 src/usr.sbin/ldpd/Makefile:1.4 --- src/usr.sbin/ldpd/Makefile:1.3 Thu Dec 30 11:29:21 2010 +++ src/usr.sbin/ldpd/Makefile Mon Nov 12 18:39:00 2012 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.3 2010/12/30 11:29:21 kefren Exp $ +# $NetBSD: Makefile,v 1.4 2012/11/12 18:39:00 kefren Exp $ .include bsd.own.mk @@ -22,4 +22,8 @@ SRCS= conffile.c \ LDADD+= -lcrypt +.if (${USE_INET6} != no) +CPPFLAGS+=-DINET6 +.endif + .include bsd.prog.mk Index: src/usr.sbin/ldpd/conffile.c diff -u src/usr.sbin/ldpd/conffile.c:1.3 src/usr.sbin/ldpd/conffile.c:1.4 --- src/usr.sbin/ldpd/conffile.c:1.3 Tue Jun 14 11:28:51 2011 +++ src/usr.sbin/ldpd/conffile.c Mon Nov 12 18:39:00 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: conffile.c,v 1.3 2011/06/14 11:28:51 kefren Exp $ */ +/* $NetBSD: conffile.c,v 1.4 2012/11/12 18:39:00 kefren Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -45,7 +45,7 @@ #define LINEMAXSIZE 1024 extern int ldp_hello_time, ldp_keepalive_time, ldp_holddown_time, command_port, - min_label, max_label, no_default_route; + min_label, max_label, no_default_route, loop_detection; int confh; struct in_addr conf_ldp_id; @@ -62,6 +62,7 @@ static int Fldpid(char*); static int Fneighbour(char*); static int Gneighbour(struct conf_neighbour *, char *); static int Fnodefault(char*); +static int Floopdetection(char*); struct conf_func { char com[64]; @@ -79,6 +80,7 @@ struct conf_func main_commands[] = { { neighbor, Fneighbour }, { neighbour, Fneighbour }, { no-default-route, Fnodefault }, + { loop-detection, Floopdetection }, { , NULL }, }; @@ -312,3 +314,13 @@ Fnodefault(char *line) no_default_route = nd; return 0; } + +int +Floopdetection(char *line) +{ + int loopd = atoi(line); + if (loopd 0) + return E_CONF_PARAM; + loop_detection = loopd; + return 0; +} Index: src/usr.sbin/ldpd/ldp.h diff -u src/usr.sbin/ldpd/ldp.h:1.3 src/usr.sbin/ldpd/ldp.h:1.4 --- src/usr.sbin/ldpd/ldp.h:1.3 Thu Jun 16 14:48:30 2011 +++ src/usr.sbin/ldpd/ldp.h Mon Nov 12 18:39:00 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: ldp.h,v 1.3 2011/06/16 14:48:30 kefren Exp $ */ +/* $NetBSD: ldp.h,v 1.4 2012/11/12 18:39:00 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -36,10 +36,11 @@ #include netinet/in.h #define ALL_ROUTERS 224.0.0.2 +#define ALL_ROUTERS6 FF02::2 #define LDP_PORT 646 #define LDP_COMMAND_PORT 2626 -#define LDPD_VER 0.3.0 +#define LDPD_VER 0.4.0 #define CONFFILE /etc/ldpd.conf Index: src/usr.sbin/ldpd/ldp_peer.c diff -u src/usr.sbin/ldpd/ldp_peer.c:1.3 src/usr.sbin/ldpd/ldp_peer.c:1.4 --- src/usr.sbin/ldpd/ldp_peer.c:1.3 Thu Dec 30 11:29:21 2010 +++ src/usr.sbin/ldpd/ldp_peer.c Mon Nov 12 18:39:00 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: ldp_peer.c,v 1.3 2010/12/30 11:29:21 kefren Exp $ */ +/* $NetBSD: ldp_peer.c,v 1.4 2012/11/12 18:39:00 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -68,7 +68,8 @@ ldp_peer_init(void) */ struct ldp_peer * ldp_peer_new(struct in_addr * ldp_id, struct in_addr * a, - struct in_addr * tradd, uint16_t holdtime, int soc) + struct in_addr * tradd, struct in6_addr * tradd6, + uint16_t holdtime, int soc) { struct ldp_peer *p; int s = soc; Index: src/usr.sbin/ldpd/fsm.c diff -u src/usr.sbin/ldpd/fsm.c:1.5 src/usr.sbin/ldpd/fsm.c:1.6 --- src/usr.sbin/ldpd/fsm.c:1.5 Thu Jun 16 14:48:30 2011 +++ src/usr.sbin/ldpd/fsm.c Mon Nov 12 18:39:00 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: fsm.c,v 1.5 2011/06/16 14:48:30 kefren Exp $ */ +/* $NetBSD: fsm.c,v 1.6 2012/11/12 18:39:00 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -56,6 +56,7 @@ run_ldp_hello(struct ldp_pdu * pduid, st { struct ldp_peer *peer = NULL; struct in_addr
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: wiz Date: Mon Nov 12 22:46:59 UTC 2012 Modified Files: src/usr.sbin/ldpd: ldpd.8 Log Message: New sentence, new line. Bump date for previous. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/ldpd/ldpd.8 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/ldpd.8 diff -u src/usr.sbin/ldpd/ldpd.8:1.6 src/usr.sbin/ldpd/ldpd.8:1.7 --- src/usr.sbin/ldpd/ldpd.8:1.6 Mon Nov 12 18:39:00 2012 +++ src/usr.sbin/ldpd/ldpd.8 Mon Nov 12 22:46:59 2012 @@ -1,4 +1,4 @@ -.\ $NetBSD: ldpd.8,v 1.6 2012/11/12 18:39:00 kefren Exp $ +.\ $NetBSD: ldpd.8,v 1.7 2012/11/12 22:46:59 wiz Exp $ .\ .\ Copyright (c) 2010 The NetBSD Foundation, Inc. .\ All rights reserved. @@ -24,7 +24,7 @@ .\ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\ POSSIBILITY OF SUCH DAMAGE. .\ -.Dd July 7, 2011 +.Dd November 12, 2012 .Dt LDPD 8 .Os .Sh NAME @@ -42,7 +42,8 @@ almost conforming to RFC5036. Right now some features requested by RFC5036 are not fully implemented. For more information please consult the .Sx BUGS -section. As a security measure you SHOULD filter the LDP well-known (646) +section. +As a security measure you SHOULD filter the LDP well-known (646) TCP and UDP ports using your favourite packet filter before starting .Nm . This is the current way used to filter neighbours and to protect the
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: christos Date: Mon Nov 12 22:51:42 UTC 2012 Modified Files: src/usr.sbin/ldpd: socketops.c Log Message: fix the build; ssize_t is %zd not %lu To generate a diff of this commit: cvs rdiff -u -r1.12 -r1.13 src/usr.sbin/ldpd/socketops.c 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/socketops.c diff -u src/usr.sbin/ldpd/socketops.c:1.12 src/usr.sbin/ldpd/socketops.c:1.13 --- src/usr.sbin/ldpd/socketops.c:1.12 Mon Nov 12 13:39:00 2012 +++ src/usr.sbin/ldpd/socketops.c Mon Nov 12 17:51:42 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: socketops.c,v 1.12 2012/11/12 18:39:00 kefren Exp $ */ +/* $NetBSD: socketops.c,v 1.13 2012/11/12 22:51:42 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -436,7 +436,7 @@ send_hello(void) if (sb (ssize_t)(IPV4_HELLO_MSG_SIZE)) fatalp(send: %s, strerror(errno)); else - debugp(Sent (IP4) %lu bytes on %s + debugp(Sent (IP4) %zd bytes on %s (PDU: %d, Hello TLV: %d, CH: %d, TR: %d)\n, sb, ifb-ifa_name, ntohs(spdu-length), ntohs(t-length),
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: pgoyette Date: Tue Nov 13 01:08:52 UTC 2012 Modified Files: src/usr.sbin/ldpd: socketops.c Log Message: Repair another %lu -- %zd - this one was caught by building for evbmips port To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 src/usr.sbin/ldpd/socketops.c 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/socketops.c diff -u src/usr.sbin/ldpd/socketops.c:1.13 src/usr.sbin/ldpd/socketops.c:1.14 --- src/usr.sbin/ldpd/socketops.c:1.13 Mon Nov 12 22:51:42 2012 +++ src/usr.sbin/ldpd/socketops.c Tue Nov 13 01:08:51 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: socketops.c,v 1.13 2012/11/12 22:51:42 christos Exp $ */ +/* $NetBSD: socketops.c,v 1.14 2012/11/13 01:08:51 pgoyette Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -492,7 +492,7 @@ send_hello(void) if (sb (ssize_t)(IPV6_HELLO_MSG_SIZE)) fatalp(send6 on %s: %s, ifb-ifa_name, strerror(errno)); else - debugp(Sent (IPv6) %lu bytes on %s + debugp(Sent (IPv6) %zd bytes on %s (PDU: %d, Hello TLV: %d, CH: %d TR: %d)\n, sb, ifb-ifa_name, htons(spdu-length), htons(t-length),
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Tue Nov 13 06:58:59 UTC 2012 Modified Files: src/usr.sbin/ldpd: socketops.c Log Message: Use local-link address as source for hellos To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/usr.sbin/ldpd/socketops.c 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/socketops.c diff -u src/usr.sbin/ldpd/socketops.c:1.14 src/usr.sbin/ldpd/socketops.c:1.15 --- src/usr.sbin/ldpd/socketops.c:1.14 Tue Nov 13 01:08:51 2012 +++ src/usr.sbin/ldpd/socketops.c Tue Nov 13 06:58:58 2012 @@ -1,4 +1,4 @@ -/* $NetBSD: socketops.c,v 1.14 2012/11/13 01:08:51 pgoyette Exp $ */ +/* $NetBSD: socketops.c,v 1.15 2012/11/13 06:58:58 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -468,6 +468,14 @@ send_hello(void) continue; if (IN6_IS_ADDR_LOOPBACK(if_sa6-sin6_addr)) continue; + /* + * draft-ietf-mpls-ldp-ipv6-07 Section 5.1: + * Additionally, the link-local + * IPv6 address MUST be used as the source IP address in IPv6 + * LDP Link Hellos. + */ + if (IN6_IS_ADDR_LINKLOCAL(if_sa6-sin6_addr) == 0) + continue; /* Send only once per interface, using primary address */ if (strcmp(ifb-ifa_name, lastifname) == 0)
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: christos Date: Sat Dec 24 23:51:27 UTC 2011 Modified Files: src/usr.sbin/ldpd: ldp_command.c Log Message: PR/45662: Henning Petersen: Overlapping buffer in lpd_command.c To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/ldpd/ldp_command.c 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/ldp_command.c diff -u src/usr.sbin/ldpd/ldp_command.c:1.5 src/usr.sbin/ldpd/ldp_command.c:1.6 --- src/usr.sbin/ldpd/ldp_command.c:1.5 Thu Jun 16 04:27:28 2011 +++ src/usr.sbin/ldpd/ldp_command.c Sat Dec 24 18:51:27 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: ldp_command.c,v 1.5 2011/06/16 08:27:28 kefren Exp $ */ +/* $NetBSD: ldp_command.c,v 1.6 2011/12/24 23:51:27 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -486,10 +486,9 @@ show_labels(int s, char *recvspace) if (p-state != LDP_PEER_ESTABLISHED) continue; SLIST_FOREACH(lm, p-label_mapping_head, mappings) { - snprintf(sendspace, MAXSEND, %s:%d, - inet_ntoa(p-ldp_id), lm-label); - snprintf(sendspace, MAXSEND, %s\t%s/%d\n, - sendspace, inet_ntoa(lm-address), lm-prefix); + snprintf(sendspace, MAXSEND, %s:%d\t%s/%d\n, + inet_ntoa(p-ldp_id), lm-label, + inet_ntoa(lm-address), lm-prefix); writestr(s, sendspace); } }
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Thu Jul 7 05:20:16 UTC 2011 Modified Files: src/usr.sbin/ldpd: ldpd.8 Log Message: Mention that it doesn't support Path Vectors and Hop Counts Mention RFC3037 and xref ldpd.conf To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/ldpd/ldpd.8 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/ldpd.8 diff -u src/usr.sbin/ldpd/ldpd.8:1.4 src/usr.sbin/ldpd/ldpd.8:1.5 --- src/usr.sbin/ldpd/ldpd.8:1.4 Fri Dec 31 06:15:08 2010 +++ src/usr.sbin/ldpd/ldpd.8 Thu Jul 7 05:20:16 2011 @@ -1,4 +1,4 @@ -.\ $NetBSD: ldpd.8,v 1.4 2010/12/31 06:15:08 wiz Exp $ +.\ $NetBSD: ldpd.8,v 1.5 2011/07/07 05:20:16 kefren Exp $ .\ .\ Copyright (c) 2010 The NetBSD Foundation, Inc. .\ All rights reserved. @@ -24,7 +24,7 @@ .\ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\ POSSIBILITY OF SUCH DAMAGE. .\ -.Dd December 7, 2010 +.Dd July 7, 2011 .Dt LDPD 8 .Os .Sh NAME @@ -79,6 +79,9 @@ Specifies a path to the config file. Default: .Pa /etc/ldpd.conf +- see +.Xr ldpd.conf 5 +for configuration file format. .It Fl D Enable debug mode. .It Fl d @@ -100,6 +103,12 @@ .%D January 2001 .%T LDP Specification .Re +.Rs +.%R RFC +.%N 3037 +.%D January 2001 +.%T LDP Applicability +.Re .Sh HISTORY The .Nm @@ -107,4 +116,4 @@ .Nx 6.0 . .Sh BUGS .Nm -supports only IPv4. +supports only IPv4 and doesn't implement Path Vector and Hop Count TLVs.
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Sat Jul 2 18:17:12 UTC 2011 Modified Files: src/usr.sbin/ldpd: main.c Log Message: return EXIT_SUCCESS and EXIT_FAILURE instead on 0 and -1 To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/ldpd/main.c 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/main.c diff -u src/usr.sbin/ldpd/main.c:1.5 src/usr.sbin/ldpd/main.c:1.6 --- src/usr.sbin/ldpd/main.c:1.5 Tue Jun 14 11:28:51 2011 +++ src/usr.sbin/ldpd/main.c Sat Jul 2 18:17:12 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.5 2011/06/14 11:28:51 kefren Exp $ */ +/* $NetBSD: main.c,v 1.6 2011/07/02 18:17:12 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -89,7 +89,7 @@ case 'p': if ((command_port = atoi(optarg)) 1) { print_usage(argv[0]); -return -1; +return EXIT_FAILURE; } break; case 'W': @@ -98,26 +98,26 @@ case 'h': default: print_usage(argv[0]); - return -1; + return EXIT_FAILURE; break; } if (geteuid()) { fatalp(You have to run this as ROOT\n); - return -1; + return EXIT_FAILURE; } cpf = conf_parsefile(conffile); if (cpf 0 strcmp(conffile, CONFFILE)) { fatalp(Cannot parse config file: %s\n, conffile); - return -1; + return EXIT_FAILURE; } else if (cpf 0) { fatalp(Cannot parse line %d in config file\n, cpf); - return -1; + return EXIT_FAILURE; } if (set_my_ldp_id()) { fatalp(Cannot set LDP ID\n); - return -1; + return EXIT_FAILURE; } if (conf_ldp_id.s_addr != 0) strlcpy(my_ldp_id, inet_ntoa(conf_ldp_id), INET_ADDRSTRLEN); @@ -125,30 +125,30 @@ if (mplssockaddr.sa_len == 0) { fatalp(You need one mpls interface up and an IP address set for it\n); - return -1; + return EXIT_FAILURE; } if (mpls_start_ldp() == -1) - return -1; + return EXIT_FAILURE; if (!strcmp(LDP_ID, 0.0.0.0)) { fatalp(Cannot set my LDP ID.\nAre you sure you've got a non-loopback INET interface UP ?\n); - return -1; + return EXIT_FAILURE; } init_command_sockets(); if ((command_socket = create_command_socket(command_port)) 1) { fatalp(Cannot create command socket\n); - return -1; + return EXIT_FAILURE; } if (create_hello_socket() 1) { fatalp(Cannot create hello socket\n); - return -1; + return EXIT_FAILURE; } ls = create_listening_socket(); if (ls 0) { fatalp(Cannot create listening socket\n); - return -1; + return EXIT_FAILURE; } if (dontfork == 1) @@ -162,5 +162,5 @@ if (forkres 0) perror(fork); - return 0; + return EXIT_SUCCESS; }
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Thu Jun 16 06:05:48 UTC 2011 Modified Files: src/usr.sbin/ldpd: socketops.c Log Message: clear the error condition KNF a little bit To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/usr.sbin/ldpd/socketops.c 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/socketops.c diff -u src/usr.sbin/ldpd/socketops.c:1.8 src/usr.sbin/ldpd/socketops.c:1.9 --- src/usr.sbin/ldpd/socketops.c:1.8 Wed Jun 15 13:24:48 2011 +++ src/usr.sbin/ldpd/socketops.c Thu Jun 16 06:05:47 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: socketops.c,v 1.8 2011/06/15 13:24:48 kefren Exp $ */ +/* $NetBSD: socketops.c,v 1.9 2011/06/16 06:05:47 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -657,13 +657,14 @@ p = get_ldp_peer_by_socket(pfd[i].fd); if (!p) continue; -if ((getsockopt(pfd[i].fd, SOL_SOCKET, SO_ERROR, - sock_error, sock_error_size) != 0) || - (sock_error)) { - ldp_peer_holddown(p); - } else { - p-state = LDP_PEER_CONNECTED; - send_initialize(p); +if (getsockopt(pfd[i].fd, SOL_SOCKET, SO_ERROR, +sock_error, sock_error_size) != 0 || +sock_error != 0) { + ldp_peer_holddown(p); + sock_error = 0; +} else { + p-state = LDP_PEER_CONNECTED; + send_initialize(p); } } }
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Thu Jun 16 07:11:52 UTC 2011 Modified Files: src/usr.sbin/ldpd: mpls_routes.c Log Message: shorten some execution paths related to check_route() and get_route() statify a bit don't assume AF_INET in a debug message To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/ldpd/mpls_routes.c 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/mpls_routes.c diff -u src/usr.sbin/ldpd/mpls_routes.c:1.6 src/usr.sbin/ldpd/mpls_routes.c:1.7 --- src/usr.sbin/ldpd/mpls_routes.c:1.6 Tue Jun 14 11:28:51 2011 +++ src/usr.sbin/ldpd/mpls_routes.c Thu Jun 16 07:11:51 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: mpls_routes.c,v 1.6 2011/06/14 11:28:51 kefren Exp $ */ +/* $NetBSD: mpls_routes.c,v 1.7 2011/06/16 07:11:51 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -59,11 +59,12 @@ int rt_seq = 0; int dont_catch = 0; extern int no_default_route; +extern int debug_f, warn_f; struct rt_msg replay_rt[REPLAY_MAX]; int replay_index = 0; -int read_route_socket(char *, int); +static int read_route_socket(char *, int); void mask_addr(union sockunion *); int compare_sockunion(union sockunion *, union sockunion *); char * mpls_ntoa(union mpls_shim); @@ -79,7 +80,7 @@ #define GETNEXT(sunion) \ (union sockunion *) ((char *) (sunion) + RT_ROUNDUP((sunion)-sa.sa_len)) -int +static int read_route_socket(char *s, int max) { int rv, to_read; @@ -509,7 +510,7 @@ rlen, l, strerror(errno)); return LDP_E_NO_SUCH_ROUTE; } else - do { + for ( ; ; ) { rlen = read_route_socket((char *) rg, sizeof(struct rt_msg)); if (rlen 1) @@ -519,27 +520,20 @@ * For now I just try to save this messages and replay * them later */ - if ((rg-m_rtm.rtm_pid != getpid()) || - (rg-m_rtm.rtm_seq != myseq)) { -/* - * Shortcut: my pid but not - * the expected sequence - */ -if (rg-m_rtm.rtm_pid == getpid()) - continue; - -debugp(Added to replay PID: %d, SEQ: %d\n, -rg-m_rtm.rtm_pid, rg-m_rtm.rtm_seq); -memcpy(replay_rt[replay_index], rg, -sizeof(struct rt_msg)); -if (replay_index REPLAY_MAX - 1) - replay_index++; -continue; - } - } while ((rg-m_rtm.rtm_seq != myseq) || - (rg-m_rtm.rtm_pid != getpid())); + if (rg-m_rtm.rtm_pid == getpid() + rg-m_rtm.rtm_seq == myseq) +break; + debugp(Added to replay PID: %d, SEQ: %d\n, + rg-m_rtm.rtm_pid, rg-m_rtm.rtm_seq); + memcpy(replay_rt[replay_index], rg, + sizeof(struct rt_msg)); + if (replay_index REPLAY_MAX - 1) +replay_index++; + else +fatalp(Replay index is full\n); + } - if ((uint)rlen = sizeof(struct rt_msghdr)) { + if (rlen = (int)sizeof(struct rt_msghdr)) { debugp(Got only %d bytes, expecting at least %u\n, rlen, sizeof(struct rt_msghdr)); return LDP_E_ROUTE_ERROR; @@ -681,6 +675,12 @@ break; } + if (!debug_f !warn_f) { + if(so_pref_allocated) + free(so_pref); + return LDP_E_OK; + } + /* Rest is just for debug */ if (so_dest) @@ -880,8 +880,9 @@ so_pref = GETNEXT(so_dst); if (so_gate-sa.sa_family == AF_MPLS) { - debugp(MPLS route to %s deleted.\n, - inet_ntoa(so_dst-sin.sin_addr)); + if (so_dst-sa.sa_family == AF_INET) +debugp(MPLS route to %s deleted.\n, +inet_ntoa(so_dst-sin.sin_addr)); delete_route(so_dst, so_pref, NO_FREESO); continue; }
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Thu Jun 16 08:27:28 UTC 2011 Modified Files: src/usr.sbin/ldpd: ldp_command.c ldp_command.h Log Message: Introduce 'show labels' command that reports about labels received from unsolicited label-maps. Statify. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/ldpd/ldp_command.c cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/ldpd/ldp_command.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/ldp_command.c diff -u src/usr.sbin/ldpd/ldp_command.c:1.4 src/usr.sbin/ldpd/ldp_command.c:1.5 --- src/usr.sbin/ldpd/ldp_command.c:1.4 Fri Dec 31 11:29:33 2010 +++ src/usr.sbin/ldpd/ldp_command.c Thu Jun 16 08:27:28 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: ldp_command.c,v 1.4 2010/12/31 11:29:33 kefren Exp $ */ +/* $NetBSD: ldp_command.c,v 1.5 2011/06/16 08:27:28 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -60,10 +60,34 @@ #define MAXSEND 1024 char sendspace[MAXSEND]; +static void send_prompt(int); +static void send_pwd_prompt(int); +static int command_match(struct com_func*, int, char*, char*); + static int verify_root_pwd(char *); static void echo_on(int s); static void echo_off(int s); +/* Main functions */ +static int show_func(int, char *); +static int set_func(int, char *); +static int exit_func(int, char *); + +/* Show functions */ +static int show_neighbours(int, char *); +static int show_bindings(int, char *); +static int show_debug(int, char *); +static int show_hellos(int, char *); +static int show_labels(int, char *); +static int show_parameters(int, char *); +static int show_version(int, char *); +static int show_warning(int, char *); + +/* Set functions */ +static int set_hello_time(int, char *); +static int set_debug(int, char *); +static int set_warning(int, char *); + static struct com_func main_commands[] = { { show, show_func }, { set, set_func }, @@ -77,6 +101,7 @@ { bindings, show_bindings }, { debug, show_debug }, { hellos, show_hellos }, + { labels, show_labels }, { parameters, show_parameters }, { version, show_version }, { warning, show_warning }, @@ -90,7 +115,7 @@ { , NULL } }; -int +static int verify_root_pwd(char *pw) { struct passwd *p; @@ -254,25 +279,27 @@ } } -void +static void send_prompt(int s) { writestr(s, LDP ); } -void +static void send_pwd_prompt(int s) { echo_off(s); writestr(s, Password: ); } -static void echo_off(int s) +static void +echo_off(int s) { char iac_will_echo[3] = { 0xff, 0xfb, 0x01 }, bf[32]; write(s, iac_will_echo, sizeof(iac_will_echo)); read(s, bf, sizeof(bf)); } -static void echo_on(int s) +static void +echo_on(int s) { char iac_wont_echo[3] = { 0xff, 0xfc, 0x01 }, bf[32]; write(s, iac_wont_echo, sizeof(iac_wont_echo)); @@ -283,7 +310,7 @@ * Matching function * Returns 1 if matched anything */ -int +static int command_match(struct com_func *cf, int s, char *orig, char *next) { size_t i, len; @@ -332,7 +359,7 @@ /* * Main CLI functions */ -int +static int set_func(int s, char *recvspace) { char *nextc = recvspace; @@ -348,7 +375,7 @@ return 0; } -int +static int show_func(int s, char *recvspace) { char *nextc = recvspace; @@ -364,7 +391,7 @@ return 0; } -int +static int exit_func(int s, char *recvspace) { command_close(s); @@ -374,7 +401,7 @@ /* * Show functions */ -int +static int show_neighbours(int s, char *recvspace) { struct ldp_peer *p; @@ -448,7 +475,28 @@ return 1; } -int +/* Shows labels grabbed from unsolicited label maps */ +static int +show_labels(int s, char *recvspace) +{ + struct ldp_peer *p; + struct label_mapping *lm; + + SLIST_FOREACH(p, ldp_peer_head, peers) { + if (p-state != LDP_PEER_ESTABLISHED) + continue; + SLIST_FOREACH(lm, p-label_mapping_head, mappings) { + snprintf(sendspace, MAXSEND, %s:%d, + inet_ntoa(p-ldp_id), lm-label); + snprintf(sendspace, MAXSEND, %s\t%s/%d\n, + sendspace, inet_ntoa(lm-address), lm-prefix); + writestr(s, sendspace); + } + } + return 1; +} + +static int show_bindings(int s, char *recvspace) { struct label *l; @@ -471,7 +519,7 @@ return 1; } -int +static int show_debug(int s, char *recvspace) { if (recvspace) { @@ -485,7 +533,7 @@ return 1; } -int +static int show_hellos(int s, char *recvspace) { struct hello_info *hi; @@ -498,7 +546,7 @@ return 1; } -int +static int show_parameters(int s, char *recvspace) { snprintf(sendspace, MAXSEND, LDP ID: %s\nProtocol version: %d\n @@ -515,7 +563,7 @@ return 1; } -int +static int show_version(int s, char *recvspace) { if (recvspace) { /* Nothing more after this */ @@ -529,7 +577,7 @@ return 1; } -int +static int show_warning(int s, char *recvspace) { if (recvspace) { @@ -544,7 +592,7 @@ } /* Set commands */ -int +static int set_hello_time(int s, char *recvspace) {
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Thu Jun 16 14:48:30 UTC 2011 Modified Files: src/usr.sbin/ldpd: fsm.c ldp.h socketops.c Log Message: obey RFC3036 3.5.2 regarding holdtimes wire SIGINT To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/ldpd/fsm.c cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/ldpd/ldp.h cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/ldpd/socketops.c 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.4 src/usr.sbin/ldpd/fsm.c:1.5 --- src/usr.sbin/ldpd/fsm.c:1.4 Tue Jun 14 11:23:02 2011 +++ src/usr.sbin/ldpd/fsm.c Thu Jun 16 14:48:30 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: fsm.c,v 1.4 2011/06/14 11:23:02 kefren Exp $ */ +/* $NetBSD: fsm.c,v 1.5 2011/06/16 14:48:30 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -91,8 +91,14 @@ debugp(Common hello Type: 0x%.4X Length: %.2d R:%d T:%d Hold time: %d\n, ht-ch.type, ht-ch.length, ht-ch.tr / 2, ht-ch.tr % 2, ht-ch.holdtime); - if (ht-ch.holdtime) + if (ht-ch.holdtime != 0) hi-keepalive = ht-ch.holdtime; + else { + if (ht-ch.res 15 == 0) + hi-keepalive = LDP_HELLO_KEEP; + else + hi-keepalive = LDP_THELLO_KEEP; + } if (!get_ldp_peer(pduid-ldp_id)) { /* First of all set peer_addr to announced LDP_ID */ memcpy(peer_addr, pduid-ldp_id, Index: src/usr.sbin/ldpd/ldp.h diff -u src/usr.sbin/ldpd/ldp.h:1.2 src/usr.sbin/ldpd/ldp.h:1.3 --- src/usr.sbin/ldpd/ldp.h:1.2 Thu Dec 30 11:29:21 2010 +++ src/usr.sbin/ldpd/ldp.h Thu Jun 16 14:48:30 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: ldp.h,v 1.2 2010/12/30 11:29:21 kefren Exp $ */ +/* $NetBSD: ldp.h,v 1.3 2011/06/16 14:48:30 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -66,6 +66,7 @@ /* Various timers */ #define LDP_HELLO_TIME 5 #define LDP_HELLO_KEEP 15 +#define LDP_THELLO_KEEP 45 #define LDP_KEEPALIVE_TIME 4 #define LDP_HOLDTIME 15 Index: src/usr.sbin/ldpd/socketops.c diff -u src/usr.sbin/ldpd/socketops.c:1.9 src/usr.sbin/ldpd/socketops.c:1.10 --- src/usr.sbin/ldpd/socketops.c:1.9 Thu Jun 16 06:05:47 2011 +++ src/usr.sbin/ldpd/socketops.c Thu Jun 16 14:48:30 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: socketops.c,v 1.9 2011/06/16 06:05:47 kefren Exp $ */ +/* $NetBSD: socketops.c,v 1.10 2011/06/16 14:48:30 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -504,7 +504,8 @@ /* Decrement hello info keepalives */ SLIST_FOREACH(hi, hello_info_head, infos) - hi-keepalive--; + if (hi-keepalive != 0x) + hi-keepalive--; /* Check hello keepalives */ SLIST_FOREACH_SAFE(hi, hello_info_head, infos, hinext) @@ -544,6 +545,7 @@ signal(SIGALRM, send_hello_alarm); signal(SIGPIPE, SIG_IGN); + signal(SIGINT, bail_out); signal(SIGTERM, bail_out); send_hello_alarm(1);
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Thu Jun 16 20:42:15 UTC 2011 Modified Files: src/usr.sbin/ldpd: mpls_routes.c Log Message: Correct prefixlen-sockaddr calculation. Now ldpd may finally allow MPLS forwarding for default route. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/ldpd/mpls_routes.c 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/mpls_routes.c diff -u src/usr.sbin/ldpd/mpls_routes.c:1.7 src/usr.sbin/ldpd/mpls_routes.c:1.8 --- src/usr.sbin/ldpd/mpls_routes.c:1.7 Thu Jun 16 07:11:51 2011 +++ src/usr.sbin/ldpd/mpls_routes.c Thu Jun 16 20:42:15 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: mpls_routes.c,v 1.7 2011/06/16 07:11:51 kefren Exp $ */ +/* $NetBSD: mpls_routes.c,v 1.8 2011/06/16 20:42:15 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -208,11 +208,7 @@ from_cidr_to_union(uint8_t prefixlen) { union sockunion *u; - int32_t n = -1; - uint32_t *m = (uint32_t*)n; - - *m = (*m (32 - prefixlen) ) (32 - prefixlen); - *m = ntohl(*m); + uint32_t m = 0x; u = calloc(1, sizeof(*u)); @@ -222,10 +218,12 @@ } u-sin.sin_len = sizeof(struct sockaddr_in); u-sin.sin_family = AF_INET; - u-sin.sin_addr.s_addr = *m; - + if (prefixlen != 0) { + m = (m (32 - prefixlen) ) (32 - prefixlen); + m = ntohl(m); + u-sin.sin_addr.s_addr = m; + } return u; - } uint8_t
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Wed Jun 15 13:24:48 UTC 2011 Modified Files: src/usr.sbin/ldpd: socketops.c Log Message: simplify the rtsock read sequence apply a little bit of KNF To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/ldpd/socketops.c 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/socketops.c diff -u src/usr.sbin/ldpd/socketops.c:1.7 src/usr.sbin/ldpd/socketops.c:1.8 --- src/usr.sbin/ldpd/socketops.c:1.7 Tue Jun 14 11:28:51 2011 +++ src/usr.sbin/ldpd/socketops.c Wed Jun 15 13:24:48 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: socketops.c,v 1.7 2011/06/14 11:28:51 kefren Exp $ */ +/* $NetBSD: socketops.c,v 1.8 2011/06/15 13:24:48 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -614,37 +614,30 @@ if (pollsum = MAX_POLL_FDS) { fatalp(Too many sockets. Increase MAX_POLL_FDS\n); return LDP_E_TOO_MANY_FDS; - } + } if (poll(pfd, pollsum, INFTIM) 0) { if (errno != EINTR) fatalp(poll: %s, strerror(errno)); continue; - } + } for (i = 0; i pollsum; i++) { if ((pfd[i].revents POLLRDNORM) || (pfd[i].revents POLLIN)) { -if(pfd[i].fd == ls) { +if(pfd[i].fd == ls) new_peer_connection(); -} else if (pfd[i].fd == route_socket) { +else if (pfd[i].fd == route_socket) { struct rt_msg xbuf; - int l, to_read; + int l; do { - l = recv(route_socket, xbuf, - sizeof(struct rt_msg), MSG_PEEK); + l = read(route_socket, xbuf, + sizeof(xbuf)); } while ((l == -1) (errno == EINTR)); if (l == -1) break; - to_read = l; - l = 0; - do { - l += recv(route_socket, xbuf, - to_read - l, MSG_WAITALL); - } while (l != to_read); - - check_route(xbuf, to_read); + check_route(xbuf, l); } else if (pfd[i].fd == hello_socket) { /* Receiving hello socket */
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Wed Jun 15 18:16:48 UTC 2011 Modified Files: src/usr.sbin/ldpd: tlv_stack.c Log Message: we need to add mapping even if there is no route for the prefix To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/ldpd/tlv_stack.c 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/tlv_stack.c diff -u src/usr.sbin/ldpd/tlv_stack.c:1.3 src/usr.sbin/ldpd/tlv_stack.c:1.4 --- src/usr.sbin/ldpd/tlv_stack.c:1.3 Thu Feb 10 12:44:41 2011 +++ src/usr.sbin/ldpd/tlv_stack.c Wed Jun 15 18:16:48 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: tlv_stack.c,v 1.3 2011/02/10 12:44:41 kefren Exp $ */ +/* $NetBSD: tlv_stack.c,v 1.4 2011/06/15 18:16:48 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -110,14 +110,13 @@ debugp(Prefix/Host add: %s/%d\n, inet_ntoa(inatmp), pref-prelen); - /* don't bother if we don't have a label/route */ - if (label_get_by_prefix(inatmp, pref-prelen) == NULL) -break; - ldp_peer_add_mapping(p, inatmp, pref-prelen, ntohl(l-label)); - mpls_add_label(p, NULL, inatmp, pref-prelen, - ntohl(l-label), 1); + + /* Try to change RIB only if label is installed */ + if (label_get_by_prefix(inatmp, pref-prelen) != NULL) +mpls_add_label(p, NULL, inatmp, pref-prelen, +ntohl(l-label), 1); break; case FEC_WILDCARD: fatalp(LDP: Wildcard add from peer %s\n,
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Tue Jun 14 11:23:02 UTC 2011 Modified Files: src/usr.sbin/ldpd: fsm.c Log Message: Use IN_LOOPBACKNET where is the case Don't forget to freeifaddrs() in case of error Update a couple of debug messages To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/ldpd/fsm.c 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.3 src/usr.sbin/ldpd/fsm.c:1.4 --- src/usr.sbin/ldpd/fsm.c:1.3 Mon Dec 13 01:25:19 2010 +++ src/usr.sbin/ldpd/fsm.c Tue Jun 14 11:23:02 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: fsm.c,v 1.3 2010/12/13 01:25:19 christos Exp $ */ +/* $NetBSD: fsm.c,v 1.4 2011/06/14 11:23:02 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -50,7 +50,7 @@ struct sockaddr mplssockaddr; /* Processing a hello */ -void +void run_ldp_hello(struct ldp_pdu * pduid, struct hello_tlv * ht, struct in_addr * padd, struct in_addr * ladd, int mysock) { @@ -62,7 +62,7 @@ if ((!pduid) || (!ht)) return; - debugp(Received it on address: %s\n, inet_ntoa(*ladd)); + debugp(Hello received for address: %s\n, inet_ntoa(*ladd)); debugp(Hello: Type: 0x%.4X Length: %.2d ID: %.8X\n, ht-type, ht-length, ht-messageid); @@ -73,7 +73,7 @@ if (hi == NULL) { hi = malloc(sizeof(*hi)); if (!hi) { - fatalp(Cannot alloc a hello info); + fatalp(Cannot alloc a hello info structure); return; } hi-ldp_id.s_addr = pduid-ldp_id.s_addr; @@ -143,13 +143,14 @@ if ((ifb-ifa_addr-sa_family == AF_INET) (ifb-ifa_flags IFF_UP)) { sa = (struct sockaddr_in *) ifb-ifa_addr; - if (sa-sin_addr.s_addr 24 24 != 127) + if (ntohl(sa-sin_addr.s_addr) 24 != IN_LOOPBACKNET) adrcount++; } t = malloc(sizeof(*t) + (adrcount - 1) * sizeof(struct in_addr)); if (!t) { fatalp(build_address_list_tlv: malloc problem\n); + freeifaddrs(ifa); return NULL; } @@ -191,7 +192,7 @@ struct sockaddr_in *sa; a.s_addr = 0; - my_ldp_id[0] = 0; + my_ldp_id[0] = '\0'; mplssockaddr.sa_len = 0; if (getifaddrs(ifa) == -1) @@ -208,7 +209,7 @@ continue; sa = (struct sockaddr_in *) ifb-ifa_addr; - if (ntohl(sa-sin_addr.s_addr) 24 == 127) + if (ntohl(sa-sin_addr.s_addr) 24 == IN_LOOPBACKNET) continue; /* No 127/8 */ if (ntohl(sa-sin_addr.s_addr) ntohl(a.s_addr)) a.s_addr = sa-sin_addr.s_addr;
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Tue Jun 14 11:28:51 UTC 2011 Modified Files: src/usr.sbin/ldpd: conffile.c ldp_errors.h main.c mpls_interface.c mpls_routes.c socketops.c socketops.h Log Message: * add no-default-route option into configuration file and check it before rejecting default-route * exit process in case of error into the main loop * complete FSM for RTM_CHANGE * Check if we overflow pollfd array To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/ldpd/conffile.c cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/ldpd/ldp_errors.h \ src/usr.sbin/ldpd/socketops.h cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/ldpd/main.c cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/ldpd/mpls_interface.c \ src/usr.sbin/ldpd/mpls_routes.c cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/ldpd/socketops.c 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/conffile.c diff -u src/usr.sbin/ldpd/conffile.c:1.2 src/usr.sbin/ldpd/conffile.c:1.3 --- src/usr.sbin/ldpd/conffile.c:1.2 Thu Dec 30 21:26:00 2010 +++ src/usr.sbin/ldpd/conffile.c Tue Jun 14 11:28:51 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: conffile.c,v 1.2 2010/12/30 21:26:00 christos Exp $ */ +/* $NetBSD: conffile.c,v 1.3 2011/06/14 11:28:51 kefren Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -45,7 +45,7 @@ #define LINEMAXSIZE 1024 extern int ldp_hello_time, ldp_keepalive_time, ldp_holddown_time, command_port, - min_label, max_label; + min_label, max_label, no_default_route; int confh; struct in_addr conf_ldp_id; @@ -61,6 +61,7 @@ static int Fldpid(char*); static int Fneighbour(char*); static int Gneighbour(struct conf_neighbour *, char *); +static int Fnodefault(char*); struct conf_func { char com[64]; @@ -77,6 +78,7 @@ { LDP-ID, Fldpid }, { neighbor, Fneighbour }, { neighbour, Fneighbour }, + { no-default-route, Fnodefault }, { , NULL }, }; @@ -300,3 +302,13 @@ } return -1; } + +int +Fnodefault(char *line) +{ + int nd = atoi(line); + if (nd 0) + return E_CONF_PARAM; + no_default_route = nd; + return 0; +} Index: src/usr.sbin/ldpd/ldp_errors.h diff -u src/usr.sbin/ldpd/ldp_errors.h:1.1 src/usr.sbin/ldpd/ldp_errors.h:1.2 --- src/usr.sbin/ldpd/ldp_errors.h:1.1 Wed Dec 8 07:20:14 2010 +++ src/usr.sbin/ldpd/ldp_errors.h Tue Jun 14 11:28:51 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: ldp_errors.h,v 1.1 2010/12/08 07:20:14 kefren Exp $ */ +/* $NetBSD: ldp_errors.h,v 1.2 2011/06/14 11:28:51 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -47,6 +47,7 @@ #define LDP_E_NO_BINDING 12 #define LDP_E_TOO_MANY_LABELS 13 #define LDP_E_INVAL 14 +#define LDP_E_TOO_MANY_FDS 15 #define LDP_E_GENERIC 255 void printtime(void); Index: src/usr.sbin/ldpd/socketops.h diff -u src/usr.sbin/ldpd/socketops.h:1.1 src/usr.sbin/ldpd/socketops.h:1.2 --- src/usr.sbin/ldpd/socketops.h:1.1 Wed Dec 8 07:20:15 2010 +++ src/usr.sbin/ldpd/socketops.h Tue Jun 14 11:28:51 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: socketops.h,v 1.1 2010/12/08 07:20:15 kefren Exp $ */ +/* $NetBSD: socketops.h,v 1.2 2011/06/14 11:28:51 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -50,7 +50,7 @@ int create_listening_socket(void); void send_hello(void); int get_message_id(void); -void the_big_loop(void); +int the_big_loop(void); void new_peer_connection(void); void send_initialize(struct ldp_peer *); void keep_alive(struct ldp_peer *); Index: src/usr.sbin/ldpd/main.c diff -u src/usr.sbin/ldpd/main.c:1.4 src/usr.sbin/ldpd/main.c:1.5 --- src/usr.sbin/ldpd/main.c:1.4 Fri Dec 31 06:16:17 2010 +++ src/usr.sbin/ldpd/main.c Tue Jun 14 11:28:51 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.4 2010/12/31 06:16:17 wiz Exp $ */ +/* $NetBSD: main.c,v 1.5 2011/06/14 11:28:51 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -152,12 +152,12 @@ } if (dontfork == 1) - the_big_loop(); + return the_big_loop(); forkres = fork(); if (forkres == 0) { syslog_f = 1; - the_big_loop(); + return the_big_loop(); } if (forkres 0) perror(fork); Index: src/usr.sbin/ldpd/mpls_interface.c diff -u src/usr.sbin/ldpd/mpls_interface.c:1.5 src/usr.sbin/ldpd/mpls_interface.c:1.6 --- src/usr.sbin/ldpd/mpls_interface.c:1.5 Wed Feb 9 11:38:57 2011 +++ src/usr.sbin/ldpd/mpls_interface.c Tue Jun 14 11:28:51 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: mpls_interface.c,v 1.5 2011/02/09 11:38:57 kefren Exp $ */ +/* $NetBSD: mpls_interface.c,v 1.6 2011/06/14 11:28:51 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -50,6 +50,8 @@ #include mpls_interface.h #include mpls_routes.h +extern int no_default_route; + int mpls_add_label(struct ldp_peer * p, struct rt_msg * inh_rg, struct in_addr * addr, int len, int label, int rlookup) @@ -66,8 +68,8 @@ debugp(Trying to add %s/%d as label %d to peer %s\n, inet_ntoa(*addr), len, label, padd);
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Mon Feb 14 11:43:59 UTC 2011 Modified Files: src/usr.sbin/ldpd: mpls_routes.c Log Message: get rid of unused variable/assignments To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/ldpd/mpls_routes.c 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/mpls_routes.c diff -u src/usr.sbin/ldpd/mpls_routes.c:1.4 src/usr.sbin/ldpd/mpls_routes.c:1.5 --- src/usr.sbin/ldpd/mpls_routes.c:1.4 Wed Feb 9 11:38:57 2011 +++ src/usr.sbin/ldpd/mpls_routes.c Mon Feb 14 11:43:59 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: mpls_routes.c,v 1.4 2011/02/09 11:38:57 kefren Exp $ */ +/* $NetBSD: mpls_routes.c,v 1.5 2011/02/14 11:43:59 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -635,25 +635,23 @@ */ /* First of all check if we already know this one */ - lab = label_get(so_dest, so_pref); - if (!lab) { + if (label_get(so_dest, so_pref) == NULL) { if (!(rg-m_rtm.rtm_flags RTF_GATEWAY)) -lab = label_add(so_dest, so_pref, NULL, +label_add(so_dest, so_pref, NULL, MPLS_LABEL_IMPLNULL, NULL, 0); else { pm = ldp_test_mapping(so_dest-sin.sin_addr, prefixlen, so_gate-sin.sin_addr); if (pm) { - lab = label_add(so_dest, so_pref, + label_add(so_dest, so_pref, so_gate, 0, NULL, 0); mpls_add_label(pm-peer, rg, so_dest-sin.sin_addr, prefixlen, pm-lm-label, ROUTE_LOOKUP_LOOP); free(pm); } else - lab = label_add(so_dest, so_pref, - so_gate, MPLS_LABEL_IMPLNULL, - NULL, 0); + label_add(so_dest, so_pref, so_gate, + MPLS_LABEL_IMPLNULL, NULL, 0); } } else /* We already know about this prefix */ debugp(Binding already there for prefix %s/%d !\n, @@ -728,7 +726,6 @@ char *buf, *next, *lim; struct rt_msghdr *rtmes; union sockunion *so_dst, *so_pref, *so_gate; - struct label *lab; mib[0] = CTL_NET; mib[1] = PF_ROUTE; @@ -812,7 +809,7 @@ continue; } if (so_gate-sa.sa_family == AF_INET) - lab = label_add(so_dst, so_pref, so_gate, + label_add(so_dst, so_pref, so_gate, MPLS_LABEL_IMPLNULL, NULL, 0); if (rtmes-rtm_flags RTF_HOST)
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Thu Feb 10 12:44:41 UTC 2011 Modified Files: src/usr.sbin/ldpd: tlv_stack.c Log Message: stop processing a label mapping message if we don't have a route for it. This way we avoid failing an assert later in mpls_add_label() To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/ldpd/tlv_stack.c 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/tlv_stack.c diff -u src/usr.sbin/ldpd/tlv_stack.c:1.2 src/usr.sbin/ldpd/tlv_stack.c:1.3 --- src/usr.sbin/ldpd/tlv_stack.c:1.2 Thu Dec 9 00:10:59 2010 +++ src/usr.sbin/ldpd/tlv_stack.c Thu Feb 10 12:44:41 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: tlv_stack.c,v 1.2 2010/12/09 00:10:59 christos Exp $ */ +/* $NetBSD: tlv_stack.c,v 1.3 2011/02/10 12:44:41 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -109,6 +109,11 @@ memcpy(inatmp, pref-prefix, ldp_ceil8(pref-prelen)); debugp(Prefix/Host add: %s/%d\n, inet_ntoa(inatmp), pref-prelen); + + /* don't bother if we don't have a label/route */ + if (label_get_by_prefix(inatmp, pref-prelen) == NULL) +break; + ldp_peer_add_mapping(p, inatmp, pref-prelen, ntohl(l-label)); mpls_add_label(p, NULL, inatmp, pref-prelen,
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Wed Feb 9 11:38:57 UTC 2011 Modified Files: src/usr.sbin/ldpd: mpls_interface.c mpls_routes.c Log Message: use RT_ROUNDUP provided by net/route.h To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/ldpd/mpls_interface.c cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/ldpd/mpls_routes.c 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/mpls_interface.c diff -u src/usr.sbin/ldpd/mpls_interface.c:1.4 src/usr.sbin/ldpd/mpls_interface.c:1.5 --- src/usr.sbin/ldpd/mpls_interface.c:1.4 Tue Jan 4 10:18:42 2011 +++ src/usr.sbin/ldpd/mpls_interface.c Wed Feb 9 11:38:57 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: mpls_interface.c,v 1.4 2011/01/04 10:18:42 kefren Exp $ */ +/* $NetBSD: mpls_interface.c,v 1.5 2011/02/09 11:38:57 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -32,6 +32,7 @@ #include arpa/inet.h #include netinet/in.h #include netmpls/mpls.h +#include net/route.h #include sys/param.h @@ -49,9 +50,6 @@ #include mpls_interface.h #include mpls_routes.h -#define ROUNDUP(a) \ - ((a) 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long)) - int mpls_add_label(struct ldp_peer * p, struct rt_msg * inh_rg, struct in_addr * addr, int len, int label, int rlookup) @@ -116,7 +114,7 @@ so_gate = (union sockunion *) rgp-m_space; so_gate = (union sockunion *)((char*)so_gate + - ROUNDUP(so_gate-sa.sa_len)); + RT_ROUNDUP(so_gate-sa.sa_len)); if (rgp-m_rtm.rtm_addrs RTA_IFA) { int li = 1; so_oldifa = so_gate; @@ -128,7 +126,7 @@ li++; for (int i = 0; i li; i++) so_oldifa = (union sockunion *)((char*)so_oldifa + - ROUNDUP(so_oldifa-sa.sa_len)); + RT_ROUNDUP(so_oldifa-sa.sa_len)); } if (so_gate-sa.sa_family != AF_INET) { Index: src/usr.sbin/ldpd/mpls_routes.c diff -u src/usr.sbin/ldpd/mpls_routes.c:1.3 src/usr.sbin/ldpd/mpls_routes.c:1.4 --- src/usr.sbin/ldpd/mpls_routes.c:1.3 Tue Jan 4 10:58:15 2011 +++ src/usr.sbin/ldpd/mpls_routes.c Wed Feb 9 11:38:57 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: mpls_routes.c,v 1.3 2011/01/04 10:58:15 kefren Exp $ */ +/* $NetBSD: mpls_routes.c,v 1.4 2011/02/09 11:38:57 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -71,14 +71,12 @@ /* Many lines inspired or shamelessly stolen from sbin/route/route.c */ -#define ROUNDUP(a) \ - ((a) 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long)) #define NEXTADDR(u) \ - do { l = ROUNDUP(u-sa.sa_len); memcpy(cp, u, l); cp += l; } while(0); + do { l = RT_ROUNDUP(u-sa.sa_len); memcpy(cp, u, l); cp += l; } while(0); #define NEXTADDR2(u) \ - do { l = ROUNDUP(u.sa_len); memcpy(cp, u, l); cp += l; } while(0); + do { l = RT_ROUNDUP(u.sa_len); memcpy(cp, u, l); cp += l; } while(0); #define GETNEXT(sunion) \ - (union sockunion *) ((char *) (sunion) + ROUNDUP((sunion)-sa.sa_len)) + (union sockunion *) ((char *) (sunion) + RT_ROUNDUP((sunion)-sa.sa_len)) int read_route_socket(char *s, int max)
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Sat Jan 22 19:35:01 UTC 2011 Modified Files: src/usr.sbin/ldpd: socketops.c Log Message: use SLIST_FOREACH_SAFE when deleting a peer in loop To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/ldpd/socketops.c 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/socketops.c diff -u src/usr.sbin/ldpd/socketops.c:1.3 src/usr.sbin/ldpd/socketops.c:1.4 --- src/usr.sbin/ldpd/socketops.c:1.3 Thu Dec 30 11:29:21 2010 +++ src/usr.sbin/ldpd/socketops.c Sat Jan 22 19:35:00 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: socketops.c,v 1.3 2010/12/30 11:29:21 kefren Exp $ */ +/* $NetBSD: socketops.c,v 1.4 2011/01/22 19:35:00 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -457,7 +457,7 @@ void send_hello_alarm(int unused) { - struct ldp_peer *p; + struct ldp_peer *p, *ptmp; struct hello_info *hi, *hinext; time_t t = time(NULL); int olderrno = errno; @@ -471,15 +471,14 @@ p-timeout--; /* Check for timeout */ -check_peer: - SLIST_FOREACH(p, ldp_peer_head, peers) + SLIST_FOREACH_SAFE(p, ldp_peer_head, peers, ptmp) if (p-timeout 1) switch (p-state) { case LDP_PEER_HOLDDOWN: debugp(LDP holddown expired for peer %s\n, inet_ntoa(p-ldp_id)); ldp_peer_delete(p); -goto check_peer; +break; case LDP_PEER_ESTABLISHED: case LDP_PEER_CONNECTED: send_notification(p, 0,
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Sat Jan 22 19:46:46 UTC 2011 Modified Files: src/usr.sbin/ldpd: socketops.c Log Message: avoid advertising 0/8 transport address (conforming RFC1122 Section 3.2.1.3) To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/ldpd/socketops.c 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/socketops.c diff -u src/usr.sbin/ldpd/socketops.c:1.4 src/usr.sbin/ldpd/socketops.c:1.5 --- src/usr.sbin/ldpd/socketops.c:1.4 Sat Jan 22 19:35:00 2011 +++ src/usr.sbin/ldpd/socketops.c Sat Jan 22 19:46:46 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: socketops.c,v 1.4 2011/01/22 19:35:00 kefren Exp $ */ +/* $NetBSD: socketops.c,v 1.5 2011/01/22 19:46:46 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -311,7 +311,8 @@ if_sa = (struct sockaddr_in *) ifb-ifa_addr; if (if_sa-sin_family != AF_INET) continue; - if (ntohl(if_sa-sin_addr.s_addr) 24 == IN_LOOPBACKNET) + if (ntohl(if_sa-sin_addr.s_addr) 24 == IN_LOOPBACKNET || + ntohl(if_sa-sin_addr.s_addr) 24 == 0) continue; /* Send only once per interface, using master address */ if (strcmp(ifb-ifa_name, lastifname) == 0)
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: wiz Date: Tue Jan 4 09:42:21 UTC 2011 Modified Files: src/usr.sbin/ldpd: mpls_interface.c Log Message: Fix memory leak in error case. Found by cppcheck. XXX: so_tag has same problem? To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/ldpd/mpls_interface.c 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/mpls_interface.c diff -u src/usr.sbin/ldpd/mpls_interface.c:1.2 src/usr.sbin/ldpd/mpls_interface.c:1.3 --- src/usr.sbin/ldpd/mpls_interface.c:1.2 Thu Dec 9 00:10:59 2010 +++ src/usr.sbin/ldpd/mpls_interface.c Tue Jan 4 09:42:21 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: mpls_interface.c,v 1.2 2010/12/09 00:10:59 christos Exp $ */ +/* $NetBSD: mpls_interface.c,v 1.3 2011/01/04 09:42:21 wiz Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -198,6 +198,7 @@ so_ifa = malloc(sizeof(*so_ifa)); if (!so_ifa) { fatalp(Out of memory\n); + free(so_nexthop); return LDP_E_MEMORY; } memcpy(so_ifa, so_oldifa, so_oldifa-sa.sa_len);
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Tue Jan 4 10:18:42 UTC 2011 Modified Files: src/usr.sbin/ldpd: mpls_interface.c Log Message: Fix more memory leaks in case malloc fails To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/ldpd/mpls_interface.c 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/mpls_interface.c diff -u src/usr.sbin/ldpd/mpls_interface.c:1.3 src/usr.sbin/ldpd/mpls_interface.c:1.4 --- src/usr.sbin/ldpd/mpls_interface.c:1.3 Tue Jan 4 09:42:21 2011 +++ src/usr.sbin/ldpd/mpls_interface.c Tue Jan 4 10:18:42 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: mpls_interface.c,v 1.3 2011/01/04 09:42:21 wiz Exp $ */ +/* $NetBSD: mpls_interface.c,v 1.4 2011/01/04 10:18:42 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -83,10 +83,12 @@ * let's loop until we have it.. */ - so_dest = make_inet_union(inet_ntoa(*addr)); - if (len != 32) - so_pref = from_cidr_to_union(len); - + if ((so_dest = make_inet_union(inet_ntoa(*addr))) == NULL) + return LDP_E_MEMORY; + if (len != 32 (so_pref = from_cidr_to_union(len)) == NULL) { + free(so_dest); + return LDP_E_MEMORY; + } do { if (kount == rlookup) { debugp(No route for this prefix\n); @@ -166,16 +168,25 @@ so_dest = make_mpls_union(lab-binding); so_nexthop = malloc(sizeof(*so_nexthop)); if (!so_nexthop) { + free(so_dest); fatalp(Out of memory\n); return LDP_E_MEMORY; } memcpy(so_nexthop, so_gate, so_gate-sa.sa_len); - so_tag = make_mpls_union(label); + if ((so_tag = make_mpls_union(label)) == NULL) { + free(so_dest); + free(so_nexthop); + fatalp(Out of memory\n); + return LDP_E_MEMORY; + } if (add_route(so_dest, NULL, so_nexthop, NULL, so_tag, FREESO, RTM_ADD) != LDP_E_OK) return LDP_E_ROUTE_ERROR; /* Now, let's add tag to IPv4 route and point it to mpls interface */ - so_dest = make_inet_union(inet_ntoa(*addr)); + if ((so_dest = make_inet_union(inet_ntoa(*addr))) == NULL) { + fatalp(Out of memory\n); + return LDP_E_MEMORY; + } /* if prefixlen == 32 check if it's inserted as host * and treat it as host. It may also be set as /32 prefix @@ -183,12 +194,18 @@ */ if ((len == 32) (rgp-m_rtm.rtm_flags RTF_HOST)) so_pref = NULL; - else - so_pref = from_cidr_to_union(len); + else if ((so_pref = from_cidr_to_union(len)) == NULL) { + free(so_dest); + fatalp(Out of memory\n); + return LDP_E_MEMORY; + } /* Add tag to route */ so_nexthop = malloc(sizeof(*so_nexthop)); if (!so_nexthop) { + free(so_dest); + if (so_pref != NULL) + free(so_pref); fatalp(Out of memory\n); return LDP_E_MEMORY; } @@ -196,9 +213,13 @@ so_tag = make_mpls_union(label); if (so_oldifa != NULL) { so_ifa = malloc(sizeof(*so_ifa)); - if (!so_ifa) { - fatalp(Out of memory\n); + if (so_ifa == NULL) { + free(so_dest); + if (so_pref != NULL) +free(so_pref); + free(so_tag); free(so_nexthop); + fatalp(Out of memory\n); return LDP_E_MEMORY; } memcpy(so_ifa, so_oldifa, so_oldifa-sa.sa_len);
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Fri Dec 31 11:29:34 UTC 2010 Modified Files: src/usr.sbin/ldpd: ldp_command.c Log Message: show in neighbour information if peer is MD5 authenticated To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/ldpd/ldp_command.c 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/ldp_command.c diff -u src/usr.sbin/ldpd/ldp_command.c:1.3 src/usr.sbin/ldpd/ldp_command.c:1.4 --- src/usr.sbin/ldpd/ldp_command.c:1.3 Thu Dec 30 11:29:21 2010 +++ src/usr.sbin/ldpd/ldp_command.c Fri Dec 31 11:29:33 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: ldp_command.c,v 1.3 2010/12/30 11:29:21 kefren Exp $ */ +/* $NetBSD: ldp_command.c,v 1.4 2010/12/31 11:29:33 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -32,6 +32,7 @@ #include arpa/inet.h #include netinet/in.h +#include netinet/tcp.h #include sys/socket.h #include sys/queue.h @@ -380,6 +381,8 @@ struct ldp_peer_address *wp; struct sockaddr_in ssin; socklen_t sin_len = sizeof(struct sockaddr_in); + int enc; + socklen_t enclen = sizeof(enc); SLIST_FOREACH(p, ldp_peer_head, peers) { snprintf(sendspace, MAXSEND, LDP peer: %s\n, @@ -410,6 +413,15 @@ if (getsockname(p-socket,(struct sockaddr *) ssin, sin_len)) break; + + if (getsockopt(p-socket, IPPROTO_TCP, TCP_MD5SIG, + enc, enclen) == 0) { +snprintf(sendspace, MAXSEND, +Authenticated: %s\n, +enc != 0 ? YES : NO); +writestr(s, sendspace); + } + snprintf(sendspace, MAXSEND,Socket: %d\nLocal %s:%d\n, p-socket, inet_ntoa(ssin.sin_addr), ntohs(ssin.sin_port));
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Thu Dec 30 11:29:22 UTC 2010 Modified Files: src/usr.sbin/ldpd: Makefile TODO label.c ldp.h ldp_command.c ldp_peer.c ldpd.8 main.c socketops.c Added Files: src/usr.sbin/ldpd: conffile.c conffile.h Log Message: * add config file so one can control id, timers and label assignment and use neighbour specific options - XXX: needs documentation * add peer authentication using TCP_MD5SIG. Interoperability tested with Cisco IOS * use SLIST_FOREACH_SAFE when deleting labels instead of re-looping. To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/ldpd/Makefile src/usr.sbin/ldpd/label.c \ src/usr.sbin/ldpd/ldp_command.c src/usr.sbin/ldpd/ldp_peer.c \ src/usr.sbin/ldpd/ldpd.8 src/usr.sbin/ldpd/main.c \ src/usr.sbin/ldpd/socketops.c cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/ldpd/TODO src/usr.sbin/ldpd/ldp.h cvs rdiff -u -r0 -r1.1 src/usr.sbin/ldpd/conffile.c \ src/usr.sbin/ldpd/conffile.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/Makefile diff -u src/usr.sbin/ldpd/Makefile:1.2 src/usr.sbin/ldpd/Makefile:1.3 --- src/usr.sbin/ldpd/Makefile:1.2 Sat Dec 18 04:25:37 2010 +++ src/usr.sbin/ldpd/Makefile Thu Dec 30 11:29:21 2010 @@ -1,11 +1,12 @@ -# $NetBSD: Makefile,v 1.2 2010/12/18 04:25:37 joerg Exp $ +# $NetBSD: Makefile,v 1.3 2010/12/30 11:29:21 kefren Exp $ .include bsd.own.mk PROG= ldpd MAN=ldpd.8 -SRCS= fsm.c \ +SRCS= conffile.c \ + fsm.c \ label.c \ ldp_command.c \ ldp_errors.c \ Index: src/usr.sbin/ldpd/label.c diff -u src/usr.sbin/ldpd/label.c:1.2 src/usr.sbin/ldpd/label.c:1.3 --- src/usr.sbin/ldpd/label.c:1.2 Thu Dec 9 00:10:59 2010 +++ src/usr.sbin/ldpd/label.c Thu Dec 30 11:29:21 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: label.c,v 1.2 2010/12/09 00:10:59 christos Exp $ */ +/* $NetBSD: label.c,v 1.3 2010/12/30 11:29:21 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -41,6 +41,8 @@ #include label.h #include ldp_errors.h +int min_label = MIN_LABEL, max_label = MAX_LABEL; + void label_init() { @@ -146,7 +148,7 @@ l-label = 0; /* Deletes pure MPLS route */ - if (oldbinding = MIN_LABEL) { + if (oldbinding = min_label) { u = make_mpls_union(oldbinding); delete_route(u, NULL, FREESO); } @@ -189,22 +191,15 @@ void del_all_peer_labels(struct ldp_peer * p, int readd) { - struct label *l; - int do_remove = 1; + struct label *l, *lnext; - while(do_remove == 1) { - do_remove = 0; - SLIST_FOREACH(l, label_head, labels) { - if(l-p != p) -continue; - label_reattach_route(l, readd); - label_del(l); - /* remove must not interact with foreach */ - SLIST_REMOVE(label_head, l, label, labels); - do_remove = 1; - break; /* XXX: suboptimal */ - } - } // while + SLIST_FOREACH_SAFE(l, label_head, labels, lnext) { + if(l-p != p) + continue; + label_reattach_route(l, readd); + label_del(l); + SLIST_REMOVE(label_head, l, label, labels); + } } /* @@ -251,11 +246,11 @@ get_free_local_label() { struct label *l; - uint32_t lbl; + int lbl; - for (lbl = MIN_LABEL; lbl = MAX_LABEL; lbl++) { + for (lbl = min_label; lbl = max_label; lbl++) { SLIST_FOREACH(l, label_head, labels) - if ((uint32_t)l-binding == lbl) + if (l-binding == lbl) break; if (l == NULL) return lbl; Index: src/usr.sbin/ldpd/ldp_command.c diff -u src/usr.sbin/ldpd/ldp_command.c:1.2 src/usr.sbin/ldpd/ldp_command.c:1.3 --- src/usr.sbin/ldpd/ldp_command.c:1.2 Tue Dec 14 21:32:43 2010 +++ src/usr.sbin/ldpd/ldp_command.c Thu Dec 30 11:29:21 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: ldp_command.c,v 1.2 2010/12/14 21:32:43 christos Exp $ */ +/* $NetBSD: ldp_command.c,v 1.3 2010/12/30 11:29:21 kefren Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -51,7 +51,8 @@ #include socketops.h struct com_sock csockets[MAX_COMMAND_SOCKETS]; -extern int ldp_hello_time, debug_f, warn_f; +extern int ldp_hello_time, ldp_keepalive_time, ldp_holddown_time, + min_label, max_label, debug_f, warn_f; #define writestr(soc, str) write(soc, str, strlen(str)) @@ -62,7 +63,7 @@ static void echo_on(int s); static void echo_off(int s); -struct com_func main_commands[] = { +static struct com_func main_commands[] = { { show, show_func }, { set, set_func }, { quit, exit_func }, @@ -70,7 +71,7 @@ { , NULL } }; -struct com_func show_commands[] = { +static struct com_func show_commands[] = { { neighbours, show_neighbours }, { bindings, show_bindings }, { debug, show_debug }, @@ -494,10 +495,10 @@ my_ldp_id, LDP_VERSION, ldp_hello_time, - LDP_KEEPALIVE_TIME, - LDP_HOLDTIME, - MIN_LABEL, - MAX_LABEL); + ldp_keepalive_time, + ldp_holddown_time, + min_label, + max_label); writestr(s, sendspace); return 1; } Index: src/usr.sbin/ldpd/ldp_peer.c diff -u src/usr.sbin/ldpd/ldp_peer.c:1.2
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: christos Date: Thu Dec 30 21:26:00 UTC 2010 Modified Files: src/usr.sbin/ldpd: conffile.c Log Message: - detect calloc failure - int - size_t - cache strlen - proper cast for ctype macro To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/ldpd/conffile.c 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/conffile.c diff -u src/usr.sbin/ldpd/conffile.c:1.1 src/usr.sbin/ldpd/conffile.c:1.2 --- src/usr.sbin/ldpd/conffile.c:1.1 Thu Dec 30 06:29:21 2010 +++ src/usr.sbin/ldpd/conffile.c Thu Dec 30 16:26:00 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: conffile.c,v 1.1 2010/12/30 11:29:21 kefren Exp $ */ +/* $NetBSD: conffile.c,v 1.2 2010/12/30 21:26:00 christos Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -50,7 +50,7 @@ struct in_addr conf_ldp_id; static int conf_dispatch(char*); -static int conf_readline(char*, int); +static int conf_readline(char*, size_t); static int checkeol(char*); static int Fhellotime(char*); static int Fport(char*); @@ -111,9 +111,9 @@ * Reads a line from config file */ int -conf_readline(char *buf, int bufsize) +conf_readline(char *buf, size_t bufsize) { - int i; + size_t i; for (i = 0; i bufsize; i++) { if (read(confh, buf[i], 1) != 1) { @@ -123,7 +123,7 @@ } if (buf[i] == '\n') break; - if (i == 0 isspace((int)buf[i]) != 0) { + if (i == 0 isspace((unsigned char)buf[i]) != 0) { i--; continue; } @@ -170,11 +170,12 @@ int checkeol(char *line) { - if (line[strlen(line) - 1] == ';') { - line[strlen(line) - 1] = '\0'; + size_t len = strlen(line); + if (len 0 line[len - 1] == ';') { + line[len - 1] = '\0'; return 0; } - for (uint i = 0; i strlen(line); i++) + for (size_t i = 0; i len; i++) if (line[i] == '{') return 0; return -1; @@ -273,10 +274,12 @@ return E_CONF_PARAM; nei = calloc(1, sizeof(*nei)); + if (nei == NULL) + return E_CONF_MEM; nei-address.s_addr = ad.s_addr; SLIST_INSERT_HEAD(conei_head, nei, neilist); - while(conf_readline(buf, sizeof(buf)) = 0) { + while (conf_readline(buf, sizeof(buf)) = 0) { if (buf[0] == '}') return 0; if (Gneighbour(nei, buf) == -1)
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: joerg Date: Sat Dec 18 04:25:37 UTC 2010 Modified Files: src/usr.sbin/ldpd: Makefile Log Message: Don't assign CFLAGS. Use default WARNS from usr.sbin/Makefile.inc. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/ldpd/Makefile 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/Makefile diff -u src/usr.sbin/ldpd/Makefile:1.1 src/usr.sbin/ldpd/Makefile:1.2 --- src/usr.sbin/ldpd/Makefile:1.1 Wed Dec 8 07:20:14 2010 +++ src/usr.sbin/ldpd/Makefile Sat Dec 18 04:25:37 2010 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.1 2010/12/08 07:20:14 kefren Exp $ +# $NetBSD: Makefile,v 1.2 2010/12/18 04:25:37 joerg Exp $ .include bsd.own.mk @@ -19,8 +19,6 @@ tlv.c \ tlv_stack.c -CFLAGS= -Wall -g - LDADD+= -lcrypt .include bsd.prog.mk
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: christos Date: Tue Dec 14 21:32:43 UTC 2010 Modified Files: src/usr.sbin/ldpd: ldp_command.c Log Message: fix uninitialized variable by elimination. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/ldpd/ldp_command.c 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/ldp_command.c diff -u src/usr.sbin/ldpd/ldp_command.c:1.1 src/usr.sbin/ldpd/ldp_command.c:1.2 --- src/usr.sbin/ldpd/ldp_command.c:1.1 Wed Dec 8 02:20:14 2010 +++ src/usr.sbin/ldpd/ldp_command.c Tue Dec 14 16:32:43 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: ldp_command.c,v 1.1 2010/12/08 07:20:14 kefren Exp $ */ +/* $NetBSD: ldp_command.c,v 1.2 2010/12/14 21:32:43 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -284,43 +284,47 @@ int command_match(struct com_func *cf, int s, char *orig, char *next) { - int i, matched = 0, last_match; + size_t i, len; + int last_match = -1; + const char *msg = NULL; - if (orig == NULL || orig[0] == '\0') { - send_prompt(s); - return 0; - } + if (orig == NULL || orig[0] == '\0') + goto out; if (!strcmp(orig, ?)) { - for (i=0; cf[i].func != NULL; i++) { + for (i = 0; cf[i].func != NULL; i++) { snprintf(sendspace, MAXSEND, \t%s\n, cf[i].com); writestr(s, sendspace); } - send_prompt(s); - return 0; + goto out; } - for (i=0; cf[i].func != NULL; i++) - if(strncasecmp(orig, cf[i].com, strlen(orig)) == 0) { - matched++; - last_match = i; + len = strlen(orig); + for (i = 0; cf[i].func != NULL; i++) { + if (strncasecmp(orig, cf[i].com, len) == 0) { + if (last_match != -1) { +msg = Ambiguous; +goto out; + } else +last_match = i; } - if (!matched) { - writestr(s, Unknown command. Use ? for help\n); - send_prompt(s); - return 0; } - if (matched 1) { - writestr(s, Ambiguous command. Use ? for help\n); - send_prompt(s); - return 0; + if (last_match == -1) { + msg = Unknown; + goto out; } - if(cf[last_match].func(s, next) != 0) + if (cf[last_match].func(s, next) != 0) send_prompt(s); return 1; - +out: + if (msg) { + writestr(s, msg); + writestr(s, command. Use ? for help\n); + } + send_prompt(s); + return 0; } /*
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: christos Date: Mon Dec 13 01:25:20 UTC 2010 Modified Files: src/usr.sbin/ldpd: fsm.c Log Message: fix possibly uninitialized variable To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/ldpd/fsm.c 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.2 src/usr.sbin/ldpd/fsm.c:1.3 --- src/usr.sbin/ldpd/fsm.c:1.2 Wed Dec 8 19:10:59 2010 +++ src/usr.sbin/ldpd/fsm.c Sun Dec 12 20:25:19 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: fsm.c,v 1.2 2010/12/09 00:10:59 christos Exp $ */ +/* $NetBSD: fsm.c,v 1.3 2010/12/13 01:25:19 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -82,44 +82,45 @@ /* Just update timer */ hi-keepalive = LDP_HELLO_KEEP; - if (ht-length 4) { /* Common hello parameters */ - ht-ch.type = ntohs(ht-ch.type); - ht-ch.length = ntohs(ht-ch.length); - ht-ch.holdtime = ntohs(ht-ch.holdtime); - ht-ch.res = ntohs(ht-ch.res); - debugp(Common hello Type: 0x%.4X Length: %.2d R:%d T:%d - Hold time: %d\n, ht-ch.type, ht-ch.length, - ht-ch.tr / 2, ht-ch.tr % 2, ht-ch.holdtime); - if (ht-ch.holdtime) - hi-keepalive = ht-ch.holdtime; - if (!get_ldp_peer(pduid-ldp_id)) { - /* First of all set peer_addr to announced LDP_ID */ - memcpy(peer_addr, pduid-ldp_id, - sizeof(struct in_addr)); - /* - * Now let's see if there is any transport TLV in - * there - */ - if (pduid-length - PDU_PAYLOAD_LENGTH - - sizeof(struct hello_tlv) 3) { -trtlv = (struct transport_address_tlv *) ht[1]; -if (trtlv-type == TLV_IPV4_TRANSPORT) - memcpy(peer_addr, trtlv-address, - sizeof(struct in_addr)); - } - /* - * RFC says: If A1 A2, LSR1 plays the active role; - * otherwise it is passive. - */ - if (ntohl(peer_addr.s_addr) ntohl(ladd-s_addr)) { + if (ht-length = 4) /* Common hello parameters */ + return; + ht-ch.type = ntohs(ht-ch.type); + ht-ch.length = ntohs(ht-ch.length); + ht-ch.holdtime = ntohs(ht-ch.holdtime); + ht-ch.res = ntohs(ht-ch.res); + debugp(Common hello Type: 0x%.4X Length: %.2d R:%d T:%d + Hold time: %d\n, ht-ch.type, ht-ch.length, + ht-ch.tr / 2, ht-ch.tr % 2, ht-ch.holdtime); + if (ht-ch.holdtime) + hi-keepalive = ht-ch.holdtime; + if (!get_ldp_peer(pduid-ldp_id)) { + /* First of all set peer_addr to announced LDP_ID */ + memcpy(peer_addr, pduid-ldp_id, + sizeof(struct in_addr)); + /* + * Now let's see if there is any transport TLV in + * there + */ + if (pduid-length - PDU_PAYLOAD_LENGTH - + sizeof(struct hello_tlv) 3) { + trtlv = (struct transport_address_tlv *) ht[1]; + if (trtlv-type == TLV_IPV4_TRANSPORT) +memcpy(peer_addr, trtlv-address, +sizeof(struct in_addr)); + } else + trtlv = NULL; + /* + * RFC says: If A1 A2, LSR1 plays the active role; + * otherwise it is passive. + */ + if (ntohl(peer_addr.s_addr) ntohl(ladd-s_addr)) { #define TRADDR (trtlv trtlv-type == TLV_IPV4_TRANSPORT) ? peer_addr : NULL -peer = ldp_peer_new(pduid-ldp_id, padd, - TRADDR, ht-ch.holdtime, 0); -if (!peer) - return; -if (peer peer-state == LDP_PEER_CONNECTED) - send_initialize(peer); - } + peer = ldp_peer_new(pduid-ldp_id, padd, +TRADDR, ht-ch.holdtime, 0); + if (!peer) +return; + if (peer peer-state == LDP_PEER_CONNECTED) +send_initialize(peer); } } }
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: wiz Date: Wed Dec 8 09:43:22 UTC 2010 Modified Files: src/usr.sbin/ldpd: ldpd.8 Log Message: Add all options to SYNOPSIS. New sentence, new line. Some rewording. Use more macros. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/ldpd/ldpd.8 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/ldpd.8 diff -u src/usr.sbin/ldpd/ldpd.8:1.1 src/usr.sbin/ldpd/ldpd.8:1.2 --- src/usr.sbin/ldpd/ldpd.8:1.1 Wed Dec 8 07:20:14 2010 +++ src/usr.sbin/ldpd/ldpd.8 Wed Dec 8 09:43:22 2010 @@ -1,4 +1,4 @@ -.\ $NetBSD: ldpd.8,v 1.1 2010/12/08 07:20:14 kefren Exp $ +.\ $NetBSD: ldpd.8,v 1.2 2010/12/08 09:43:22 wiz Exp $ .\ .\ Copyright (c) 2010 The NetBSD Foundation, Inc. .\ All rights reserved. @@ -25,58 +25,68 @@ .\ POSSIBILITY OF SUCH DAMAGE. .\ .Dd December 7, 2010 -.Dt ldpd 8 +.Dt LDPD 8 .Os .Sh NAME .Nm ldpd .Nd Label Distribution Protocol Daemon .Sh SYNOPSIS .Nm -.Op Fl dDW -.Bk -words +.Op Fl DdfhW .Op Fl p Ar port -.Ek .Sh DESCRIPTION .Nm is a utility used to automatically distribute labels between two MPLS LSRs -almost conforming to RFC3036. Right now is in BETA stage and many features -are not implemented or may not work. As a security measure you SHOULD filter -the LDP well-known ( 646 ) TCP and UDP ports before starting -.Nm -using your favourite packet filter. Also this is the current measure used -to filter neighbours. You should see some logs reported via +almost conforming to RFC3036. +Right now it is in BETA stage and many features +are not implemented or may not work. +As a security measure you SHOULD filter the LDP well-known (646) +TCP and UDP ports using your favourite packet filter before starting +.Nm . +Also this is the current measure used to filter neighbours. +You should see some logs reported via .Xr syslog 3 interface. .Pp -You can increase the log verbosity using -W and -D parameters. -Also you can telnet on control port (default: 2626) and use this interface -in order to get informations about protocol, neighbours etc. but also to -set runtime parameters. The required password is the same as root password. +You can increase the log verbosity using the +.Fl W +and +.Fl D +flags. +Also you can telnet to the control port (default: 2626) and use +this interface in order to get informations about protocol, neighbours +etc. but also to set runtime parameters. +The required password is the same as the root password. .Pp .Nm -computes existing routes and try to match them on MPLS labels announced by -other LDP peers. This means that 'normal' routes will be changed into tagged -routes, and MPLS routing table will be populated. It will also announce -peers about its mappings. -.Nm -will also listen on a route socket and compute the necessary changes in -order to change untagged routes into tagged routes. This means that one may -use his favourite dynamic routing protocol daemon without modifications. +computes existing routes and tries to match them on MPLS labels +announced by other LDP peers. +This means that +.Dq normal +routes will be changed into tagged routes, and MPLS routing table +will be populated. +It will also announce its mappings to its peers. +.Nm +will listen on a route socket and compute the necessary changes in +order to change untagged routes into tagged routes. +This means that one may use one's favourite dynamic routing protocol +daemon without modifications. .Pp The options are as follows: .Bl -tag -width 15n -.It Fl d -Don't use route interception code. .It Fl D Enable debug mode. +.It Fl d +Don't use route interception code. .It Fl f -Run in foreground. Use STDOUT for warning and debug messages. +Run in foreground. +Use STDOUT for warning and debug messages. .It Fl h Outputs supported flags. .It Fl p Ar port Changes the TCP control port (default: 2626). .It Fl W -Enable warning messages output. +Enable output of warning messages. .El .Sh SEE ALSO .Rs @@ -88,7 +98,8 @@ .Sh HISTORY The .Nm -command appeared in NetBSD 6.0 +command appeared in +.Nx 6.0 . .Sh BUGS .Nm -supports only IPv4 +supports only IPv4.
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: wiz Date: Wed Dec 8 09:43:28 UTC 2010 Modified Files: src/usr.sbin/ldpd: main.c Log Message: Add all options to usage. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/ldpd/main.c 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/main.c diff -u src/usr.sbin/ldpd/main.c:1.1 src/usr.sbin/ldpd/main.c:1.2 --- src/usr.sbin/ldpd/main.c:1.1 Wed Dec 8 07:20:14 2010 +++ src/usr.sbin/ldpd/main.c Wed Dec 8 09:43:28 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.1 2010/12/08 07:20:14 kefren Exp $ */ +/* $NetBSD: main.c,v 1.2 2010/12/08 09:43:28 wiz Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -60,7 +60,7 @@ void print_usage(char *myself) { - printf(\nUsage: %s [-hdDW] [-p PORT]\n\n, myself); + printf(\nUsage: %s [-DdfhW] [-p PORT]\n\n, myself); } int @@ -70,12 +70,12 @@ while((ch = getopt(argc, argv, dDfhp:W)) != -1) switch(ch) { - case 'd': - dont_catch = 1; - break; case 'D': debug_f = 1; break; + case 'd': + dont_catch = 1; + break; case 'f': dontfork = 1; break;
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: christos Date: Thu Dec 9 00:11:00 UTC 2010 Modified Files: src/usr.sbin/ldpd: fsm.c label.c ldp_peer.c mpls_interface.c mpls_routes.c notifications.c socketops.c tlv_stack.c Log Message: - no cast for malloc - malloc + memset = calloc - sizeof(type) - sizeof(*var) - small indents To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/ldpd/fsm.c src/usr.sbin/ldpd/label.c \ src/usr.sbin/ldpd/ldp_peer.c src/usr.sbin/ldpd/mpls_interface.c \ src/usr.sbin/ldpd/mpls_routes.c src/usr.sbin/ldpd/notifications.c \ src/usr.sbin/ldpd/socketops.c src/usr.sbin/ldpd/tlv_stack.c 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.1 src/usr.sbin/ldpd/fsm.c:1.2 --- src/usr.sbin/ldpd/fsm.c:1.1 Wed Dec 8 02:20:14 2010 +++ src/usr.sbin/ldpd/fsm.c Wed Dec 8 19:10:59 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: fsm.c,v 1.1 2010/12/08 07:20:14 kefren Exp $ */ +/* $NetBSD: fsm.c,v 1.2 2010/12/09 00:10:59 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -71,7 +71,7 @@ if (hi-ldp_id.s_addr == pduid-ldp_id.s_addr) break; if (hi == NULL) { - hi = (struct hello_info *)malloc(sizeof(struct hello_info)); + hi = malloc(sizeof(*hi)); if (!hi) { fatalp(Cannot alloc a hello info); return; @@ -145,13 +145,12 @@ if (sa-sin_addr.s_addr 24 24 != 127) adrcount++; } - t = (struct address_list_tlv *) malloc(sizeof(struct address_list_tlv) - + (adrcount - 1) * sizeof(struct in_addr)); + t = malloc(sizeof(*t) + (adrcount - 1) * sizeof(struct in_addr)); if (!t) { fatalp(build_address_list_tlv: malloc problem\n); return NULL; - } + } t-type = htons(LDP_ADDRESS); t-length = htons(sizeof(struct address_list_tlv) - TLV_TYPE_LENGTH Index: src/usr.sbin/ldpd/label.c diff -u src/usr.sbin/ldpd/label.c:1.1 src/usr.sbin/ldpd/label.c:1.2 --- src/usr.sbin/ldpd/label.c:1.1 Wed Dec 8 02:20:14 2010 +++ src/usr.sbin/ldpd/label.c Wed Dec 8 19:10:59 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: label.c,v 1.1 2010/12/08 07:20:14 kefren Exp $ */ +/* $NetBSD: label.c,v 1.2 2010/12/09 00:10:59 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -58,13 +58,12 @@ struct label *l; char spreftmp[INET_ADDRSTRLEN]; - l = (struct label *) malloc(sizeof(struct label)); - memset(l, 0, sizeof(struct label)); + l = calloc(1, sizeof(*l)); if (!l) { fatalp(label_add: malloc problem\n); return NULL; - } + } assert(so_dest); assert(so_pref); Index: src/usr.sbin/ldpd/ldp_peer.c diff -u src/usr.sbin/ldpd/ldp_peer.c:1.1 src/usr.sbin/ldpd/ldp_peer.c:1.2 --- src/usr.sbin/ldpd/ldp_peer.c:1.1 Wed Dec 8 02:20:14 2010 +++ src/usr.sbin/ldpd/ldp_peer.c Wed Dec 8 19:10:59 2010 @@ -1,4 +1,4 @@ -/* $NetBSD: ldp_peer.c,v 1.1 2010/12/08 07:20:14 kefren Exp $ */ +/* $NetBSD: ldp_peer.c,v 1.2 2010/12/09 00:10:59 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -87,14 +87,13 @@ } /* Set the peer in CONNECTING/CONNECTED state */ - p = (struct ldp_peer *) malloc(sizeof(struct ldp_peer)); + p = calloc(1, sizeof(*p)); if (!p) { fatalp(ldp_peer_new: malloc problem\n); return NULL; - } + } - memset(p, 0, sizeof(struct ldp_peer)); SLIST_INSERT_HEAD(ldp_peer_head, p, peers); memcpy(p-address, a, sizeof(struct in_addr)); memcpy(p-ldp_id, ldp_id, sizeof(struct in_addr)); @@ -282,14 +281,12 @@ if (check_ifaddr(p, a)) return LDP_E_ALREADY_DONE; - lpa = (struct ldp_peer_address*)malloc(sizeof(struct ldp_peer_address)); + lpa = calloc(1, sizeof(*lpa)); if (!lpa) { fatalp(add_ifaddr: malloc problem\n); return LDP_E_MEMORY; - } - - memset(lpa, 0, sizeof(struct ldp_peer_address)); + } memcpy(lpa-address, a, sizeof(struct in_addr)); @@ -355,8 +352,7 @@ void add_my_if_addrs(struct in_addr * a, int count) { - myaddresses = (struct in_addr *) malloc((count + 1) * - (sizeof(struct in_addr))); + myaddresses = calloc((count + 1), sizeof(*myaddresses)); if (!myaddresses) { fatalp(add_my_if_addrs: malloc problem\n); @@ -378,7 +374,7 @@ if (ldp_peer_get_lm(p, a, prefix)) return LDP_E_ALREADY_DONE; - lma = (struct label_mapping *) malloc(sizeof(struct label_mapping)); + lma = malloc(sizeof(*lma)); if (!lma) { fatalp(ldp_peer_add_mapping: malloc problem\n); @@ -468,7 +464,7 @@ debugp(Cannot match that prefix to the specified peer\n); return NULL; } - rv = (struct peer_map *) malloc(sizeof(struct peer_map)); + rv = malloc(sizeof(*rv)); if (!rv) { fatalp(ldp_test_mapping: malloc problem\n); Index: src/usr.sbin/ldpd/mpls_interface.c diff -u src/usr.sbin/ldpd/mpls_interface.c:1.1 src/usr.sbin/ldpd/mpls_interface.c:1.2 --- src/usr.sbin/ldpd/mpls_interface.c:1.1 Wed Dec 8 02:20:14 2010 +++ src/usr.sbin/ldpd/mpls_interface.c Wed Dec 8 19:10:59 2010 @@ -1,4 +1,4
CVS commit: src/usr.sbin/ldpd
Module Name:src Committed By: kefren Date: Wed Dec 8 07:34:08 UTC 2010 Removed Files: src/usr.sbin/ldpd: ldp.d Log Message: Remove accidentally added file To generate a diff of this commit: cvs rdiff -u -r1.1 -r0 src/usr.sbin/ldpd/ldp.d Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.