CVS commit: src

2015-05-27 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Wed May 27 18:13:14 UTC 2015

Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/net/mpls: Makefile
Added Files:
src/tests/net/mpls: t_mpls_fw64.sh

Log Message:
Add another simple MPLS test but using this time a mixed IPv4/IPv6 LSR
This test encapsulates IPv6 packets, pass them over MPLS to an IPv6
neighbour that switches label and passes forward to an IPv4
neighbour. There, the IPv6 packet is decapsulated and passed to IPv6 stack
For the return path we test both implicit and explicit null encapsulations


To generate a diff of this commit:
cvs rdiff -u -r1.626 -r1.627 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.5 -r1.6 src/tests/net/mpls/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/net/mpls/t_mpls_fw64.sh

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

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.626 src/distrib/sets/lists/tests/mi:1.627
--- src/distrib/sets/lists/tests/mi:1.626	Wed May 27 16:40:33 2015
+++ src/distrib/sets/lists/tests/mi	Wed May 27 18:13:14 2015
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.626 2015/05/27 16:40:33 kefren Exp $
+# $NetBSD: mi,v 1.627 2015/05/27 18:13:14 kefren Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -3162,6 +3162,7 @@
 ./usr/tests/net/mpls/t_ldp_static		tests-net-tests		obsolete
 ./usr/tests/net/mpls/t_mpls_fw			tests-net-tests		atf,rump
 ./usr/tests/net/mpls/t_mpls_fw6			tests-net-tests		atf,rump
+./usr/tests/net/mpls/t_mpls_fw64		tests-net-tests		atf,rump
 ./usr/tests/net/mpls/t_rfc4182			tests-net-tests		atf,rump
 ./usr/tests/net/nettests-net-tests
 ./usr/tests/net/net/Atffile			tests-net-tests		atf

Index: src/tests/net/mpls/Makefile
diff -u src/tests/net/mpls/Makefile:1.5 src/tests/net/mpls/Makefile:1.6
--- src/tests/net/mpls/Makefile:1.5	Wed May 27 16:40:33 2015
+++ src/tests/net/mpls/Makefile	Wed May 27 18:13:14 2015
@@ -1,10 +1,10 @@
-# $NetBSD: Makefile,v 1.5 2015/05/27 16:40:33 kefren Exp $
+# $NetBSD: Makefile,v 1.6 2015/05/27 18:13:14 kefren Exp $
 #
 
 .include 
 
 TESTSDIR=	${TESTSBASE}/net/mpls
 
-TESTS_SH=	t_mpls_fw t_mpls_fw6 t_rfc4182 t_ldp_regen
+TESTS_SH=	t_mpls_fw t_mpls_fw6 t_mpls_fw64 t_rfc4182 t_ldp_regen
 
 .include 

Added files:

Index: src/tests/net/mpls/t_mpls_fw64.sh
diff -u /dev/null src/tests/net/mpls/t_mpls_fw64.sh:1.1
--- /dev/null	Wed May 27 18:13:14 2015
+++ src/tests/net/mpls/t_mpls_fw64.sh	Wed May 27 18:13:14 2015
@@ -0,0 +1,230 @@
+# $NetBSD: t_mpls_fw64.sh,v 1.1 2015/05/27 18:13:14 kefren Exp $
+#
+# Copyright (c) 2015 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#notice, this list of conditions and the following disclaimer in the
+#documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+# Test MPLS encap/decap and forwarding using INET6 as encapsulated protocol
+# Setup four routers connected like this: R1---R2---R3---R4--
+# Goal is to be able to ping from R1 the outermost interface of R4
+# Disable net.inet[6].ip[6].forwarding, enable net.mpls.forwarding
+# Use IPv6 between R1-R2-R3 and IPv4 between R3-R4
+# As we use IPv4 on last link we should use only expl.null there
+# because implicit null will assume IPv4 (as the next-hop)
+# But we can use impl null on R2-R1 link because stack will correctly
+# guess IPv6 (from next-hop)
+# Add route on R1 in order to encapsulate into MPLS the IP6 packets with
+# destination equal to R4 right hand side interface
+# Add MPLS routes on R2 in order to forward frames belonging to that FEC to R3
+# Add MPLS expl.null route on R3 for that FEC, pointing to R4
+# Do the same for the reverse direction (R4 to R1)
+# ping6 from R1 to R4 right hand side interface
+
+
+RUMP_SER

CVS commit: src

2015-05-27 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Wed May 27 16:40:33 UTC 2015

Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/net/mpls: Makefile
Added Files:
src/tests/net/mpls: t_mpls_fw6.sh

Log Message:
Add a simple IPv6/MPLS test


To generate a diff of this commit:
cvs rdiff -u -r1.625 -r1.626 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.4 -r1.5 src/tests/net/mpls/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/net/mpls/t_mpls_fw6.sh

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

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.625 src/distrib/sets/lists/tests/mi:1.626
--- src/distrib/sets/lists/tests/mi:1.625	Tue May 26 22:05:44 2015
+++ src/distrib/sets/lists/tests/mi	Wed May 27 16:40:33 2015
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.625 2015/05/26 22:05:44 htodd Exp $
+# $NetBSD: mi,v 1.626 2015/05/27 16:40:33 kefren Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -3161,6 +3161,7 @@
 ./usr/tests/net/mpls/t_ldp_regen		tests-net-tests		atf,rump
 ./usr/tests/net/mpls/t_ldp_static		tests-net-tests		obsolete
 ./usr/tests/net/mpls/t_mpls_fw			tests-net-tests		atf,rump
+./usr/tests/net/mpls/t_mpls_fw6			tests-net-tests		atf,rump
 ./usr/tests/net/mpls/t_rfc4182			tests-net-tests		atf,rump
 ./usr/tests/net/nettests-net-tests
 ./usr/tests/net/net/Atffile			tests-net-tests		atf

Index: src/tests/net/mpls/Makefile
diff -u src/tests/net/mpls/Makefile:1.4 src/tests/net/mpls/Makefile:1.5
--- src/tests/net/mpls/Makefile:1.4	Tue Nov 12 12:22:33 2013
+++ src/tests/net/mpls/Makefile	Wed May 27 16:40:33 2015
@@ -1,10 +1,10 @@
-# $NetBSD: Makefile,v 1.4 2013/11/12 12:22:33 kefren Exp $
+# $NetBSD: Makefile,v 1.5 2015/05/27 16:40:33 kefren Exp $
 #
 
 .include 
 
 TESTSDIR=	${TESTSBASE}/net/mpls
 
-TESTS_SH=	t_mpls_fw t_rfc4182 t_ldp_regen
+TESTS_SH=	t_mpls_fw t_mpls_fw6 t_rfc4182 t_ldp_regen
 
 .include 

Added files:

Index: src/tests/net/mpls/t_mpls_fw6.sh
diff -u /dev/null src/tests/net/mpls/t_mpls_fw6.sh:1.1
--- /dev/null	Wed May 27 16:40:33 2015
+++ src/tests/net/mpls/t_mpls_fw6.sh	Wed May 27 16:40:33 2015
@@ -0,0 +1,224 @@
+# $NetBSD: t_mpls_fw6.sh,v 1.1 2015/05/27 16:40:33 kefren Exp $
+#
+# Copyright (c) 2015 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#notice, this list of conditions and the following disclaimer in the
+#documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+# Test MPLS encap/decap and forwarding using INET6 as encapsulated protocol
+# Setup four routers connected like this: R1---R2---R3---R4--
+# Goal is to be able to ping from R1 the outermost interface of R4
+# Disable net.inet6.ip6.forwarding, enable net.mpls.forwarding
+# Add route on R1 in order to encapsulate into MPLS the IP6 packets with
+# destination equal to R4 right hand side interface
+# Add MPLS routes on R2 in order to forward frames belonging to that FEC to R3
+# Add MPLS "POP" route on R3 for that FEC, pointing to R4
+# Do the same for the reverse direction (R4 to R1)
+# ping6 from R1 to R4 right hand side interface
+#
+# redo the test using IPv6 explicit null label
+
+RUMP_SERVER1=unix://./r1
+RUMP_SERVER2=unix://./r2
+RUMP_SERVER3=unix://./r3
+RUMP_SERVER4=unix://./r4
+
+RUMP_FLAGS6=\
+"-lrumpnet -lrumpnet_net -lrumpnet_netmpls -lrumpnet_netinet -lrumpnet_netinet6 -lrumpnet_shmif"
+
+atf_test_case mplsfw6 cleanup
+mplsfw6_head()
+{
+
+	atf_set "descr" "IP6/MPLS forwarding test using PHP"
+	atf_set "require.progs" "rump_server"
+}
+
+startservers()
+{
+
+	ulimit -r 300
+	atf_check -s exit:0 rump_server ${RUMP_FLAGS6} ${RUMP_SERVER1}
+	atf_check -s exit:0 rump_server ${RUMP_FLAGS6} ${RUMP_SERVER2}
+	atf_check -s exit:0 rump_server ${RUMP_FLAGS6} ${RUMP_SE

CVS commit: src/sys/netinet

2015-05-19 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Tue May 19 17:33:44 UTC 2015

Modified Files:
src/sys/netinet: tcp_subr.c

Log Message:
Use RUN_ONCE to initialize iss secret. Suggested by riastradh@


To generate a diff of this commit:
cvs rdiff -u -r1.261 -r1.262 src/sys/netinet/tcp_subr.c

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

Modified files:

Index: src/sys/netinet/tcp_subr.c
diff -u src/sys/netinet/tcp_subr.c:1.261 src/sys/netinet/tcp_subr.c:1.262
--- src/sys/netinet/tcp_subr.c:1.261	Sat May 16 10:09:20 2015
+++ src/sys/netinet/tcp_subr.c	Tue May 19 17:33:43 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_subr.c,v 1.261 2015/05/16 10:09:20 kefren Exp $	*/
+/*	$NetBSD: tcp_subr.c,v 1.262 2015/05/19 17:33:43 kefren Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.261 2015/05/16 10:09:20 kefren Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.262 2015/05/19 17:33:43 kefren Exp $");
 
 #include "opt_inet.h"
 #include "opt_ipsec.h"
@@ -240,6 +240,7 @@ int	tcp_syn_bucket_limit = 3*TCP_SYN_BUC
 struct	syn_cache_head tcp_syn_cache[TCP_SYN_HASH_SIZE];
 
 int	tcp_freeq(struct tcpcb *);
+static int	tcp_iss_secret_init(void);
 
 #ifdef INET
 static void	tcp_mtudisc_callback(struct in_addr);
@@ -2217,6 +2218,20 @@ tcp_new_iss(struct tcpcb *tp, tcp_seq ad
 	panic("tcp_new_iss");
 }
 
+static u_int8_t tcp_iss_secret[16];	/* 128 bits; should be plenty */
+
+/*
+ * Initialize RFC 1948 ISS Secret
+ */
+static int
+tcp_iss_secret_init(void)
+{
+	cprng_strong(kern_cprng,
+	tcp_iss_secret, sizeof(tcp_iss_secret), 0);
+
+	return 0;
+}
+
 /*
  * This routine actually generates a new TCP initial sequence number.
  */
@@ -2226,23 +2241,16 @@ tcp_new_iss1(void *laddr, void *faddr, u
 {
 	tcp_seq tcp_iss;
 
-	/* RFC1948 specifics */
-	static bool tcp_iss_gotten_secret;
-	static u_int8_t tcp_iss_secret[16];	/* 128 bits; should be plenty */
-
 	if (tcp_do_rfc1948) {
 		MD5_CTX ctx;
 		u_int8_t hash[16];	/* XXX MD5 knowledge */
+		static ONCE_DECL(tcp_iss_secret_control);
 
 		/*
 		 * If we haven't been here before, initialize our cryptographic
 		 * hash secret.
 		 */
-		if (tcp_iss_gotten_secret == false) {
-			cprng_strong(kern_cprng,
-			tcp_iss_secret, sizeof(tcp_iss_secret), 0);
-			tcp_iss_gotten_secret = true;
-		}
+		RUN_ONCE(&tcp_iss_secret_control, tcp_iss_secret_init);
 
 		/*
 		 * Compute the base value of the ISS.  It is a hash



CVS commit: src/sys/netinet

2015-05-16 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Sat May 16 10:09:20 UTC 2015

Modified Files:
src/sys/netinet: tcp_subr.c

Log Message:
Don't overexpose tcp_iss_secret and don't bother compute it unless
RFC1948 compliance is activated


To generate a diff of this commit:
cvs rdiff -u -r1.260 -r1.261 src/sys/netinet/tcp_subr.c

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

Modified files:

Index: src/sys/netinet/tcp_subr.c
diff -u src/sys/netinet/tcp_subr.c:1.260 src/sys/netinet/tcp_subr.c:1.261
--- src/sys/netinet/tcp_subr.c:1.260	Mon Apr 27 02:59:44 2015
+++ src/sys/netinet/tcp_subr.c	Sat May 16 10:09:20 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_subr.c,v 1.260 2015/04/27 02:59:44 ozaki-r Exp $	*/
+/*	$NetBSD: tcp_subr.c,v 1.261 2015/05/16 10:09:20 kefren Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.260 2015/04/27 02:59:44 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.261 2015/05/16 10:09:20 kefren Exp $");
 
 #include "opt_inet.h"
 #include "opt_ipsec.h"
@@ -2189,7 +2189,6 @@ tcp_rmx_rtt(struct tcpcb *tp)
 }
 
 tcp_seq	 tcp_iss_seq = 0;	/* tcp initial seq # */
-u_int8_t tcp_iss_secret[16];	/* 128 bits; should be plenty */
 
 /*
  * Get a new sequence value given a tcp control block
@@ -2227,23 +2226,25 @@ tcp_new_iss1(void *laddr, void *faddr, u
 {
 	tcp_seq tcp_iss;
 
+	/* RFC1948 specifics */
 	static bool tcp_iss_gotten_secret;
-
-	/*
-	 * If we haven't been here before, initialize our cryptographic
-	 * hash secret.
-	 */
-	if (tcp_iss_gotten_secret == false) {
-		cprng_strong(kern_cprng,
-			 tcp_iss_secret, sizeof(tcp_iss_secret), 0);
-		tcp_iss_gotten_secret = true;
-	}
+	static u_int8_t tcp_iss_secret[16];	/* 128 bits; should be plenty */
 
 	if (tcp_do_rfc1948) {
 		MD5_CTX ctx;
 		u_int8_t hash[16];	/* XXX MD5 knowledge */
 
 		/*
+		 * If we haven't been here before, initialize our cryptographic
+		 * hash secret.
+		 */
+		if (tcp_iss_gotten_secret == false) {
+			cprng_strong(kern_cprng,
+			tcp_iss_secret, sizeof(tcp_iss_secret), 0);
+			tcp_iss_gotten_secret = true;
+		}
+
+		/*
 		 * Compute the base value of the ISS.  It is a hash
 		 * of (saddr, sport, daddr, dport, secret).
 		 */



CVS commit: src/sys/netinet

2015-05-15 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Sat May 16 01:15:34 UTC 2015

Modified Files:
src/sys/netinet: tcp_output.c

Log Message:
Don't put segment on the wire if security request can't be fulfilled


To generate a diff of this commit:
cvs rdiff -u -r1.182 -r1.183 src/sys/netinet/tcp_output.c

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

Modified files:

Index: src/sys/netinet/tcp_output.c
diff -u src/sys/netinet/tcp_output.c:1.182 src/sys/netinet/tcp_output.c:1.183
--- src/sys/netinet/tcp_output.c:1.182	Mon Apr 27 16:50:17 2015
+++ src/sys/netinet/tcp_output.c	Sat May 16 01:15:34 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_output.c,v 1.182 2015/04/27 16:50:17 christos Exp $	*/
+/*	$NetBSD: tcp_output.c,v 1.183 2015/05/16 01:15:34 kefren Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -135,7 +135,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_output.c,v 1.182 2015/04/27 16:50:17 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_output.c,v 1.183 2015/05/16 01:15:34 kefren Exp $");
 
 #include "opt_inet.h"
 #include "opt_ipsec.h"
@@ -1238,7 +1238,10 @@ send:
 		*bp++ = TCPOPT_NOP;
 		*bp++ = TCPOPT_EOL;
  		optlen += 2;
- 	}
+ 	} else if ((tp->t_flags & TF_SIGNATURE) != 0) {
+		error = ECONNABORTED;
+		goto out;
+	}
 #endif /* TCP_SIGNATURE */
 
 	hdrlen += optlen;



CVS commit: src/sys/netinet

2015-05-15 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Fri May 15 18:03:45 UTC 2015

Modified Files:
src/sys/netinet: tcp_input.c

Log Message:
Don't try to do PCB lookup for bad checksummed segments
Fixes PR/43510 and PR/48452


To generate a diff of this commit:
cvs rdiff -u -r1.339 -r1.340 src/sys/netinet/tcp_input.c

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

Modified files:

Index: src/sys/netinet/tcp_input.c
diff -u src/sys/netinet/tcp_input.c:1.339 src/sys/netinet/tcp_input.c:1.340
--- src/sys/netinet/tcp_input.c:1.339	Sat May  2 17:18:03 2015
+++ src/sys/netinet/tcp_input.c	Fri May 15 18:03:45 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_input.c,v 1.339 2015/05/02 17:18:03 rtr Exp $	*/
+/*	$NetBSD: tcp_input.c,v 1.340 2015/05/15 18:03:45 kefren Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -148,7 +148,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.339 2015/05/02 17:18:03 rtr Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_input.c,v 1.340 2015/05/15 18:03:45 kefren Exp $");
 
 #include "opt_inet.h"
 #include "opt_ipsec.h"
@@ -1394,6 +1394,12 @@ tcp_input(struct mbuf *m, ...)
 	tiflags = th->th_flags;
 
 	/*
+	 * Checksum extended TCP header and data
+	 */
+	if (tcp_input_checksum(af, m, th, toff, off, tlen))
+		goto badcsum;
+
+	/*
 	 * Locate pcb for segment.
 	 */
 findpcb:
@@ -1564,12 +1570,6 @@ findpcb:
 	KASSERT(so->so_lock == softnet_lock);
 	KASSERT(solocked(so));
 
-	/*
-	 * Checksum extended TCP header and data.
-	 */
-	if (tcp_input_checksum(af, m, th, toff, off, tlen))
-		goto badcsum;
-
 	tcp_fields_to_host(th);
 
 	/* Unscale the window into a 32-bit value. */



CVS commit: src/sbin/ping6

2015-05-15 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Fri May 15 08:02:39 UTC 2015

Modified Files:
src/sbin/ping6: ping6.8 ping6.c

Log Message:
Add options -X for deadline and -x for reply maxwait (flag names matching
FreeBSD). Unline FreeBSD, currently -x doesn't count late packets to statistics.
After discussion with, and help from ozaki-r@
Should fix PR/49896


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sbin/ping6/ping6.8
cvs rdiff -u -r1.86 -r1.87 src/sbin/ping6/ping6.c

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

Modified files:

Index: src/sbin/ping6/ping6.8
diff -u src/sbin/ping6/ping6.8:1.29 src/sbin/ping6/ping6.8:1.30
--- src/sbin/ping6/ping6.8:1.29	Fri Apr 24 00:42:56 2015
+++ src/sbin/ping6/ping6.8	Fri May 15 08:02:39 2015
@@ -1,4 +1,4 @@
-.\"	$NetBSD: ping6.8,v 1.29 2015/04/24 00:42:56 christos Exp $
+.\"	$NetBSD: ping6.8,v 1.30 2015/05/15 08:02:39 kefren Exp $
 .\"	$KAME: ping6.8,v 1.57 2002/05/26 13:18:25 itojun Exp $
 .\"
 .\" Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -55,6 +55,8 @@ packets to network hosts
 .Op Fl P Ar policy
 .Op Fl S Ar sourceaddr
 .Op Fl s Ar packetsize
+.Op Fl x Ar maxwait
+.Op Fl X Ar deadline
 .Op Ar hops ...
 .Ar host
 .Sh DESCRIPTION
@@ -269,6 +271,11 @@ This option is present for backward comp
 has no effect if
 .Fl w
 is specified.
+.It Fl x Ar maxwait
+Time in milliseconds to wait for a reply for each packet sent.
+.It Fl X Ar deadline
+Specify a timeout, in seconds, before ping exits regardless of
+how many packets have been received.
 .It Ar hops
 IPv6 addresses for intermediate nodes,
 which will be put into type 0 routing header.

Index: src/sbin/ping6/ping6.c
diff -u src/sbin/ping6/ping6.c:1.86 src/sbin/ping6/ping6.c:1.87
--- src/sbin/ping6/ping6.c:1.86	Fri Apr 24 00:42:56 2015
+++ src/sbin/ping6/ping6.c	Fri May 15 08:02:39 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ping6.c,v 1.86 2015/04/24 00:42:56 christos Exp $	*/
+/*	$NetBSD: ping6.c,v 1.87 2015/05/15 08:02:39 kefren Exp $	*/
 /*	$KAME: ping6.c,v 1.164 2002/11/16 14:05:37 itojun Exp $	*/
 
 /*
@@ -77,7 +77,7 @@ static char sccsid[] = "@(#)ping.c	8.1 (
 #else
 #include 
 #ifndef lint
-__RCSID("$NetBSD: ping6.c,v 1.86 2015/04/24 00:42:56 christos Exp $");
+__RCSID("$NetBSD: ping6.c,v 1.87 2015/05/15 08:02:39 kefren Exp $");
 #endif
 #endif
 
@@ -235,6 +235,8 @@ static double tmin = 9.0;	/* min
 static double tmax = 0.0;		/* maximum round trip time */
 static double tsum = 0.0;		/* sum of all times, for doing average */
 static double tsumsq = 0.0;		/* sum of all times squared, for std. dev. */
+static double maxwait = 0.0;		/* maxwait for reply in ms */
+static double deadline = 0.0;		/* max running time in seconds */
 
 /* for node addresses */
 static u_short naflags;
@@ -278,6 +280,7 @@ static void	 summary(void);
 static void	 tvsub(struct timeval *, struct timeval *);
 static int	 setpolicy(int, char *);
 static char	*nigroup(char *);
+static double	timespec_to_sec(const struct timespec *tp);
 __dead static void	 usage(void);
 
 int
@@ -311,6 +314,8 @@ main(int argc, char *argv[])
 #ifdef IPV6_USE_MIN_MTU
 	int mflag = 0;
 #endif
+	struct timespec now;
+	double exitat = 0.0;
 
 	/* just to be sure */
 	memset(&smsghdr, 0, sizeof(smsghdr));
@@ -328,7 +333,7 @@ main(int argc, char *argv[])
 #endif /*IPSEC_POLICY_IPSEC*/
 #endif
 	while ((ch = getopt(argc, argv,
-	"a:b:c:dfHg:h:I:i:l:mnNop:qRS:s:tvwW" ADDOPTS)) != -1) {
+	"a:b:c:dfHg:h:I:i:l:mnNop:qRS:s:tvwWx:X:" ADDOPTS)) != -1) {
 #undef ADDOPTS
 		switch (ch) {
 		case 'a':
@@ -532,6 +537,18 @@ main(int argc, char *argv[])
 			options &= ~F_NOUSERDATA;
 			options |= F_FQDNOLD;
 			break;
+		case 'x':
+			maxwait = strtod(optarg, &e);
+			if (*e != '\0' || maxwait <= 0)
+errx(EXIT_FAILURE, "Bad/invalid maxwait time: "
+"%s", optarg);
+			break;
+		case 'X':
+			deadline = strtod(optarg, &e);
+			if (*e != '\0' || deadline <= 0)
+errx(EXIT_FAILURE, "Bad/invalid deadline time: "
+"%s", optarg);
+break;
 #ifdef IPSEC
 #ifdef IPSEC_POLICY_IPSEC
 		case 'P':
@@ -790,7 +807,7 @@ main(int argc, char *argv[])
 }
 #endif /*ICMP6_FILTER*/
 
-	/* let the kerel pass extension headers of incoming packets */
+	/* let the kernel pass extension headers of incoming packets */
 	if ((options & F_VERBOSE) != 0) {
 		int opton = 1;
 
@@ -1019,6 +1036,11 @@ main(int argc, char *argv[])
 			retransmit();
 	}
 
+	if (deadline > 0) {
+		clock_gettime(CLOCK_MONOTONIC, &now);
+		exitat = timespec_to_sec(&now) + deadline;
+	}
+
 	seenalrm = seenint = 0;
 #ifdef SIGINFO
 	seeninfo = 0;
@@ -1029,6 +1051,13 @@ main(int argc, char *argv[])
 		u_char buf[1024];
 		struct iovec iov[2];
 
+		/* check deadline */
+		if (exitat > 0) {
+			clock_gettime(CLOCK_MONOTONIC, &now);
+			if (exitat <= timespec_to_sec(&now))
+break;
+		}
+
 		/* signal handling */
 		if (seenalrm) {
 			retransmit();
@@ -1047,10 

CVS commit: src/sys/netinet

2013-12-02 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Mon Dec  2 09:39:54 UTC 2013

Modified Files:
src/sys/netinet: tcp_usrreq.c

Log Message:
Update TCP CB with new values on rfc1323 and mssdflt sysctl updates
>From yasu...@iij.ad.jp in kern/44254


To generate a diff of this commit:
cvs rdiff -u -r1.169 -r1.170 src/sys/netinet/tcp_usrreq.c

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

Modified files:

Index: src/sys/netinet/tcp_usrreq.c
diff -u src/sys/netinet/tcp_usrreq.c:1.169 src/sys/netinet/tcp_usrreq.c:1.170
--- src/sys/netinet/tcp_usrreq.c:1.169	Sat Nov 23 14:20:21 2013
+++ src/sys/netinet/tcp_usrreq.c	Mon Dec  2 09:39:54 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_usrreq.c,v 1.169 2013/11/23 14:20:21 christos Exp $	*/
+/*	$NetBSD: tcp_usrreq.c,v 1.170 2013/12/02 09:39:54 kefren Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -95,7 +95,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.169 2013/11/23 14:20:21 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_usrreq.c,v 1.170 2013/12/02 09:39:54 kefren Exp $");
 
 #include "opt_inet.h"
 #include "opt_ipsec.h"
@@ -1044,10 +1044,43 @@ sysctl_net_inet_tcp_mssdflt(SYSCTLFN_ARG
 		return (EINVAL);
 	tcp_mssdflt = mssdflt;
 
+	mutex_enter(softnet_lock);
+	tcp_tcpcb_template();
+	mutex_exit(softnet_lock);
+
 	return (0);
 }
 
 /*
+ * sysctl helper for TCP CB template update
+ */
+static int
+sysctl_update_tcpcb_template(SYSCTLFN_ARGS)
+{
+	int t, error;
+	struct sysctlnode node;
+
+	/* follow procedures in sysctl(9) manpage */
+	t = *(int *)rnode->sysctl_data;
+	node = *rnode;
+	node.sysctl_data = &t;
+	error = sysctl_lookup(SYSCTLFN_CALL(&node));
+	if (error || newp == NULL)
+		return error;
+
+	if (t < 0)
+		return EINVAL;
+
+	*(int *)rnode->sysctl_data = t;
+
+	mutex_enter(softnet_lock);
+	tcp_tcpcb_template();
+	mutex_exit(softnet_lock);
+
+	return 0;
+}
+
+/*
  * sysctl helper routine for setting port related values under
  * net.inet.ip and net.inet6.ip6.  does basic range checking and does
  * additional checks for each type.  this code has placed in
@@ -1686,7 +1719,7 @@ sysctl_net_inet_tcp_setup2(struct sysctl
 		   CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 		   CTLTYPE_INT, "rfc1323",
 		   SYSCTL_DESCR("Enable RFC1323 TCP extensions"),
-		   NULL, 0, &tcp_do_rfc1323, 0,
+		   sysctl_update_tcpcb_template, 0, &tcp_do_rfc1323, 0,
 		   CTL_NET, pf, IPPROTO_TCP, TCPCTL_RFC1323, CTL_EOL);
 	sysctl_createv(clog, 0, NULL, NULL,
 		   CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
@@ -1786,13 +1819,13 @@ sysctl_net_inet_tcp_setup2(struct sysctl
 		   CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 		   CTLTYPE_INT, "win_scale",
 		   SYSCTL_DESCR("Use RFC1323 window scale options"),
-		   NULL, 0, &tcp_do_win_scale, 0,
+		   sysctl_update_tcpcb_template, 0, &tcp_do_win_scale, 0,
 		   CTL_NET, pf, IPPROTO_TCP, TCPCTL_WSCALE, CTL_EOL);
 	sysctl_createv(clog, 0, NULL, NULL,
 		   CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 		   CTLTYPE_INT, "timestamps",
 		   SYSCTL_DESCR("Use RFC1323 time stamp options"),
-		   NULL, 0, &tcp_do_timestamps, 0,
+		   sysctl_update_tcpcb_template, 0, &tcp_do_timestamps, 0,
 		   CTL_NET, pf, IPPROTO_TCP, TCPCTL_TSTAMP, CTL_EOL);
 	sysctl_createv(clog, 0, NULL, NULL,
 		   CTLFLAG_PERMANENT|CTLFLAG_READWRITE,



CVS commit: src/distrib/sets/lists/tests

2013-11-12 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Tue Nov 12 18:28:36 UTC 2013

Modified Files:
src/distrib/sets/lists/tests: mi

Log Message:
mark t_ldp_static obsolete (this time correctly)


To generate a diff of this commit:
cvs rdiff -u -r1.550 -r1.551 src/distrib/sets/lists/tests/mi

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

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.550 src/distrib/sets/lists/tests/mi:1.551
--- src/distrib/sets/lists/tests/mi:1.550	Tue Nov 12 16:48:39 2013
+++ src/distrib/sets/lists/tests/mi	Tue Nov 12 18:28:36 2013
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.550 2013/11/12 16:48:39 joerg Exp $
+# $NetBSD: mi,v 1.551 2013/11/12 18:28:36 kefren Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -2606,7 +2606,7 @@
 ./usr/tests/net/mpls/Atffile			tests-net-tests		atf,rump
 ./usr/tests/net/mpls/Kyuafile			tests-net-tests		atf,rump,kyua
 ./usr/tests/net/mpls/t_ldp_regen		tests-net-tests		atf,rump
-./usr/tests/net/mpls/t_ldp_static		tests-net-tests		atf,rump	obsolete
+./usr/tests/net/mpls/t_ldp_static		tests-net-tests		obsolete
 ./usr/tests/net/mpls/t_mpls_fw			tests-net-tests		atf,rump
 ./usr/tests/net/mpls/t_rfc4182			tests-net-tests		atf,rump
 ./usr/tests/net/nettests-net-tests



CVS commit: src

2013-11-12 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Tue Nov 12 12:22:33 UTC 2013

Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/net/mpls: Makefile
Removed Files:
src/tests/net/mpls: t_ldp_static.sh

Log Message:
Retire t_ldp_static. It's too heavy weighted for releng's anita and mostly
unsuited for atf.


To generate a diff of this commit:
cvs rdiff -u -r1.548 -r1.549 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.3 -r1.4 src/tests/net/mpls/Makefile
cvs rdiff -u -r1.2 -r0 src/tests/net/mpls/t_ldp_static.sh

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

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.548 src/distrib/sets/lists/tests/mi:1.549
--- src/distrib/sets/lists/tests/mi:1.548	Mon Nov 11 11:10:45 2013
+++ src/distrib/sets/lists/tests/mi	Tue Nov 12 12:22:33 2013
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.548 2013/11/11 11:10:45 joerg Exp $
+# $NetBSD: mi,v 1.549 2013/11/12 12:22:33 kefren Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -2605,7 +2605,7 @@
 ./usr/tests/net/mpls/Atffile			tests-net-tests		atf,rump
 ./usr/tests/net/mpls/Kyuafile			tests-net-tests		atf,rump,kyua
 ./usr/tests/net/mpls/t_ldp_regen		tests-net-tests		atf,rump
-./usr/tests/net/mpls/t_ldp_static		tests-net-tests		atf,rump
+./usr/tests/net/mpls/t_ldp_static		tests-net-tests		atf,rump	obsolete
 ./usr/tests/net/mpls/t_mpls_fw			tests-net-tests		atf,rump
 ./usr/tests/net/mpls/t_rfc4182			tests-net-tests		atf,rump
 ./usr/tests/net/nettests-net-tests

Index: src/tests/net/mpls/Makefile
diff -u src/tests/net/mpls/Makefile:1.3 src/tests/net/mpls/Makefile:1.4
--- src/tests/net/mpls/Makefile:1.3	Thu Jul 25 14:28:29 2013
+++ src/tests/net/mpls/Makefile	Tue Nov 12 12:22:33 2013
@@ -1,10 +1,10 @@
-# $NetBSD: Makefile,v 1.3 2013/07/25 14:28:29 kefren Exp $
+# $NetBSD: Makefile,v 1.4 2013/11/12 12:22:33 kefren Exp $
 #
 
 .include 
 
 TESTSDIR=	${TESTSBASE}/net/mpls
 
-TESTS_SH=	t_mpls_fw t_rfc4182 t_ldp_regen t_ldp_static
+TESTS_SH=	t_mpls_fw t_rfc4182 t_ldp_regen
 
 .include 



CVS commit: src/sys/netinet

2013-11-12 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Tue Nov 12 09:02:05 UTC 2013

Modified Files:
src/sys/netinet: tcp_congctl.c tcp_congctl.h tcp_input.c tcp_sack.c
tcp_subr.c tcp_var.h

Log Message:
* implement TCP CUBIC congestion control algorithm
* move tcp_sack_newack bits inside reno and newreno_fast_retransmit_newack
* notify ECN peer about cwnd shrink in [new]reno_slow_retransmit

Based on the patch proposed on tech-net@ on Nov 7 with minor improvments:
 * adapt wmax for no-fast convergence case
 * correct cbrt calculation for big window sizes (>750KB)


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/netinet/tcp_congctl.c
cvs rdiff -u -r1.6 -r1.7 src/sys/netinet/tcp_congctl.h
cvs rdiff -u -r1.329 -r1.330 src/sys/netinet/tcp_input.c
cvs rdiff -u -r1.28 -r1.29 src/sys/netinet/tcp_sack.c
cvs rdiff -u -r1.250 -r1.251 src/sys/netinet/tcp_subr.c
cvs rdiff -u -r1.170 -r1.171 src/sys/netinet/tcp_var.h

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

Modified files:

Index: src/sys/netinet/tcp_congctl.c
diff -u src/sys/netinet/tcp_congctl.c:1.17 src/sys/netinet/tcp_congctl.c:1.18
--- src/sys/netinet/tcp_congctl.c:1.17	Fri Oct 25 16:29:20 2013
+++ src/sys/netinet/tcp_congctl.c	Tue Nov 12 09:02:05 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: tcp_congctl.c,v 1.17 2013/10/25 16:29:20 martin Exp $	*/
+/*	$NetBSD: tcp_congctl.c,v 1.18 2013/11/12 09:02:05 kefren Exp $	*/
 
 /*-
  * Copyright (c) 1997, 1998, 1999, 2001, 2005, 2006 The NetBSD Foundation, Inc.
@@ -135,7 +135,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tcp_congctl.c,v 1.17 2013/10/25 16:29:20 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tcp_congctl.c,v 1.18 2013/11/12 09:02:05 kefren Exp $");
 
 #include "opt_inet.h"
 #include "opt_tcp_debug.h"
@@ -194,6 +194,9 @@ __KERNEL_RCSID(0, "$NetBSD: tcp_congctl.
  *   consider separating the actual implementations in another file.
  */
 
+static void tcp_common_congestion_exp(struct tcpcb *, int, int);
+
+static int  tcp_reno_do_fast_retransmit(struct tcpcb *, const struct tcphdr *);
 static int  tcp_reno_fast_retransmit(struct tcpcb *, const struct tcphdr *);
 static void tcp_reno_slow_retransmit(struct tcpcb *);
 static void tcp_reno_fast_retransmit_newack(struct tcpcb *,
@@ -206,6 +209,10 @@ static void tcp_newreno_fast_retransmit_
 	const struct tcphdr *);
 static void tcp_newreno_newack(struct tcpcb *, const struct tcphdr *);
 
+static int tcp_cubic_fast_retransmit(struct tcpcb *, const struct tcphdr *);
+static void tcp_cubic_slow_retransmit(struct tcpcb *tp);
+static void tcp_cubic_newack(struct tcpcb *, const struct tcphdr *);
+static void tcp_cubic_congestion_exp(struct tcpcb *);
 
 static void tcp_congctl_fillnames(void);
 
@@ -241,6 +248,8 @@ tcp_congctl_init(void)
 	KASSERT(r == 0);
 	r = tcp_congctl_register("newreno", &tcp_newreno_ctl);
 	KASSERT(r == 0);
+	r = tcp_congctl_register("cubic", &tcp_cubic_ctl);
+	KASSERT(r == 0);
 
 	/* NewReno is the default. */
 #ifndef TCP_CONGCTL_DEFAULT
@@ -406,18 +415,28 @@ tcp_congctl_fillnames(void)
 /*  */
 
 /*
- * TCP/Reno congestion control.
+ * Common stuff
  */
+
+/* Window reduction (1-beta) for [New]Reno: 0.5 */
+#define RENO_BETAA 1
+#define RENO_BETAB 2
+/* Window reduction (1-beta) for Cubic: 0.8 */
+#define CUBIC_BETAA 4
+#define CUBIC_BETAB 5
+/* Draft Rhee Section 4.1 */
+#define CUBIC_CA 4
+#define CUBIC_CB 10
+
 static void
-tcp_reno_congestion_exp(struct tcpcb *tp)
+tcp_common_congestion_exp(struct tcpcb *tp, int betaa, int betab)
 {
 	u_int win;
 
 	/* 
-	 * Halve the congestion window and reduce the
-	 * slow start threshold.
+	 * Reduce the congestion window and the slow start threshold.
 	 */
-	win = min(tp->snd_wnd, tp->snd_cwnd) / 2 / tp->t_segsz;
+	win = min(tp->snd_wnd, tp->snd_cwnd) * betaa / betab / tp->t_segsz;
 	if (win < 2)
 		win = 2;
 
@@ -434,9 +453,20 @@ tcp_reno_congestion_exp(struct tcpcb *tp
 }
 
 
+/*  */
+
+/*
+ * TCP/Reno congestion control.
+ */
+static void
+tcp_reno_congestion_exp(struct tcpcb *tp)
+{
+
+	tcp_common_congestion_exp(tp, RENO_BETAA, RENO_BETAB);
+}
 
 static int
-tcp_reno_fast_retransmit(struct tcpcb *tp, const struct tcphdr *th)
+tcp_reno_do_fast_retransmit(struct tcpcb *tp, const struct tcphdr *th)
 {
 	/*
 	 * We know we're losing at the current
@@ -458,10 +488,8 @@ tcp_reno_fast_retransmit(struct tcpcb *t
 	 * irrespective of the number of DupAcks.
 	 */
 	
-	tcp_seq onxt;
-	
-	onxt = tp->snd_nxt;
-	tcp_reno_congestion_exp(tp);
+	tcp_seq onxt = tp->snd_nxt;
+
 	tp->t_partialacks = 0;
 	TCP_TIMER_DISARM(tp, TCPT_REXMT);
 	tp->t_rtttime = 0;
@@ -482,6 +510,14 @@ tcp_reno_fast_retransmit(struct tcpcb *t
 	return 0;
 }
 
+static int
+tcp_reno_fast_retransmit(struct tcpcb *tp, const struct tcphdr *th)
+{
+
+	tcp_reno_congestion_exp(tp);
+	return tcp_re

CVS commit: src/sbin/ifconfig

2013-11-09 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Sat Nov  9 13:10:35 UTC 2013

Modified Files:
src/sbin/ifconfig: ifconfig.8

Log Message:
Bring tunnel src_addr and dst_addr on the same line


To generate a diff of this commit:
cvs rdiff -u -r1.104 -r1.105 src/sbin/ifconfig/ifconfig.8

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

Modified files:

Index: src/sbin/ifconfig/ifconfig.8
diff -u src/sbin/ifconfig/ifconfig.8:1.104 src/sbin/ifconfig/ifconfig.8:1.105
--- src/sbin/ifconfig/ifconfig.8:1.104	Sat Jan 28 15:01:44 2012
+++ src/sbin/ifconfig/ifconfig.8	Sat Nov  9 13:10:35 2013
@@ -1,4 +1,4 @@
-.\"	$NetBSD: ifconfig.8,v 1.104 2012/01/28 15:01:44 mbalmer Exp $
+.\"	$NetBSD: ifconfig.8,v 1.105 2013/11/09 13:10:35 kefren Exp $
 .\"
 .\" Copyright (c) 1983, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -504,8 +504,8 @@ flag may be used to display long SSIDs.
 .Fl v
 also causes received information elements to be displayed symbolically.
 Only the super-user can use this command.
-.It Cm tunnel Ar src_addr Ns Op Ar ,src_port
-.Ar dest_addr Ns Op Ar ,dest_port
+.It Cm tunnel Ar src_addr Ns Oo Ar ,src_port Oc Ar dest_addr Ns Oo Ar ,dest_port
+.Oc
 .Pq IP tunnel devices only
 Configure the physical source and destination address for IP tunnel
 interfaces, including



CVS commit: src/usr.sbin/npf/npfctl

2013-11-05 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Tue Nov  5 13:09:12 UTC 2013

Modified Files:
src/usr.sbin/npf/npfctl: npf.conf.5

Log Message:
sync an example with the latest group syntax change


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/usr.sbin/npf/npfctl/npf.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/npf/npfctl/npf.conf.5
diff -u src/usr.sbin/npf/npfctl/npf.conf.5:1.31 src/usr.sbin/npf/npfctl/npf.conf.5:1.32
--- src/usr.sbin/npf/npfctl/npf.conf.5:1.31	Fri Sep 20 03:03:52 2013
+++ src/usr.sbin/npf/npfctl/npf.conf.5	Tue Nov  5 13:09:12 2013
@@ -1,4 +1,4 @@
-.\"$NetBSD: npf.conf.5,v 1.31 2013/09/20 03:03:52 rmind Exp $
+.\"$NetBSD: npf.conf.5,v 1.32 2013/11/05 13:09:12 kefren Exp $
 .\"
 .\" Copyright (c) 2009-2013 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd September 20, 2013
+.Dd November 5, 2013
 .Dt NPF.CONF 5
 .Os
 .Sh NAME
@@ -115,7 +115,7 @@ Groups may have the following options: n
 They are defined in the following form:
 .Pp
 .Bd -literal
-group (name "my_group", interface wm0, in) {
+group "my_group_name" in on wm0 {
 	# List of rules
 }
 .Ed



CVS commit: src/sbin/route

2013-11-04 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Tue Nov  5 07:42:48 UTC 2013

Modified Files:
src/sbin/route: route.8

Log Message:
Remove esis reference


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/sbin/route/route.8

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

Modified files:

Index: src/sbin/route/route.8
diff -u src/sbin/route/route.8:1.49 src/sbin/route/route.8:1.50
--- src/sbin/route/route.8:1.49	Mon Oct  7 05:06:45 2013
+++ src/sbin/route/route.8	Tue Nov  5 07:42:48 2013
@@ -1,4 +1,4 @@
-.\"	$NetBSD: route.8,v 1.49 2013/10/07 05:06:45 dholland Exp $
+.\"	$NetBSD: route.8,v 1.50 2013/11/05 07:42:48 kefren Exp $
 .\"
 .\" Copyright (c) 1983, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\" @(#)route.8	8.4 (Berkeley) 6/1/94
 .\"
-.Dd July 24, 2013
+.Dd November 5, 2013
 .Dt ROUTE 8
 .Os
 .Sh NAME
@@ -401,7 +401,6 @@ Only root may modify the routing tables.
 These privileges are enforced by the kernel.
 .El
 .Sh SEE ALSO
-.Xr esis 4 ,
 .Xr mpls 4 ,
 .Xr netintro 4 ,
 .Xr route 4 ,



CVS commit: src/sys/net

2013-10-25 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Fri Oct 25 09:25:32 UTC 2013

Modified Files:
src/sys/net: if_mpls.c

Log Message:
RFC3032 conformance for Router Alert Label


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/net/if_mpls.c

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

Modified files:

Index: src/sys/net/if_mpls.c
diff -u src/sys/net/if_mpls.c:1.10 src/sys/net/if_mpls.c:1.11
--- src/sys/net/if_mpls.c:1.10	Tue Jul 23 11:11:55 2013
+++ src/sys/net/if_mpls.c	Fri Oct 25 09:25:32 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_mpls.c,v 1.10 2013/07/23 11:11:55 kefren Exp $ */
+/*	$NetBSD: if_mpls.c,v 1.11 2013/10/25 09:25:32 kefren Exp $ */
 
 /*
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_mpls.c,v 1.10 2013/07/23 11:11:55 kefren Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_mpls.c,v 1.11 2013/10/25 09:25:32 kefren Exp $");
 
 #include "opt_inet.h"
 #include "opt_mpls.h"
@@ -66,6 +66,15 @@ __KERNEL_RCSID(0, "$NetBSD: if_mpls.c,v 
 
 #include "if_mpls.h"
 
+#define TRIM_LABEL do { \
+	m_adj(m, sizeof(union mpls_shim)); \
+	if (m->m_len < sizeof(union mpls_shim) && \
+	(m = m_pullup(m, sizeof(union mpls_shim))) == NULL) \
+		goto done; \
+	dst.smpls_addr.s_addr = ntohl(mtod(m, union mpls_shim *)->s_addr); \
+	} while (/* CONSTCOND */ 0)
+
+
 void ifmplsattach(int);
 
 static int mpls_clone_create(struct if_clone *, int);
@@ -308,6 +317,7 @@ mpls_lse(struct mbuf *m)
 	struct rtentry *rt = NULL;
 	int error = ENOBUFS;
 	uint psize = sizeof(struct sockaddr_mpls);
+	bool push_back_alert = false;
 
 	if (m->m_len < sizeof(union mpls_shim) &&
 	(m = m_pullup(m, sizeof(union mpls_shim))) == NULL)
@@ -330,14 +340,15 @@ mpls_lse(struct mbuf *m)
 	if (mpls_rfc4182 != 0)
 		while((dst.smpls_addr.shim.label == MPLS_LABEL_IPV4NULL ||
 		dst.smpls_addr.shim.label == MPLS_LABEL_IPV6NULL) &&
-		__predict_false(dst.smpls_addr.shim.bos == 0)) {
-			m_adj(m, sizeof(union mpls_shim));
-			if (m->m_len < sizeof(union mpls_shim) &&
-			(m = m_pullup(m, sizeof(union mpls_shim))) == NULL)
-goto done;
-			dst.smpls_addr.s_addr =
-			ntohl(mtod(m, union mpls_shim *)->s_addr);
-		}
+		__predict_false(dst.smpls_addr.shim.bos == 0))
+			TRIM_LABEL;
+
+	/* RFC 3032 Section 2.1 Page 4 */
+	if (__predict_false(dst.smpls_addr.shim.label == MPLS_LABEL_RTALERT) &&
+	dst.smpls_addr.shim.bos == 0) {
+		TRIM_LABEL;
+		push_back_alert = true;
+	}
 
 	if (dst.smpls_addr.shim.label <= MPLS_LABEL_RESMAX) {
 		/* Don't swap reserved labels */
@@ -412,6 +423,16 @@ mpls_lse(struct mbuf *m)
 		psize += sizeof(tshim);
 	}
 
+	if (__predict_false(push_back_alert == true)) {
+		/* re-add the router alert label */
+		memset(&tshim, 0, sizeof(tshim));
+		tshim.s_addr = MPLS_LABEL_RTALERT;
+		tshim.shim.bos = tshim.shim.exp = 0;
+		tshim.shim.ttl = mpls_defttl;
+		if ((m = mpls_prepend_shim(m, &tshim)) == NULL)
+			return ENOBUFS;
+	}
+
 	error = mpls_send_frame(m, rt->rt_ifp, rt);
 
 done:



CVS commit: src/usr.sbin/ldpd

2013-10-18 Thread Mihai Chelaru
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 
 #include 
-
+#include 
 #include 
 #include 
 #include 
@@ -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, sizeof(*conf_if));
-	char buf[102

CVS commit: src

2013-10-18 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Fri Oct 18 10:49:19 UTC 2013

Modified Files:
src/distrib/sets/lists/man: mi
src/usr.sbin/ldpd: Makefile
Added Files:
src/usr.sbin/ldpd: ldpd.conf.5

Log Message:
Attempt to write a manpage for ldpd.conf


To generate a diff of this commit:
cvs rdiff -u -r1.1438 -r1.1439 src/distrib/sets/lists/man/mi
cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/ldpd/Makefile
cvs rdiff -u -r0 -r1.1 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/distrib/sets/lists/man/mi
diff -u src/distrib/sets/lists/man/mi:1.1438 src/distrib/sets/lists/man/mi:1.1439
--- src/distrib/sets/lists/man/mi:1.1438	Tue Oct 15 19:20:19 2013
+++ src/distrib/sets/lists/man/mi	Fri Oct 18 10:49:19 2013
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1438 2013/10/15 19:20:19 jdc Exp $
+# $NetBSD: mi,v 1.1439 2013/10/18 10:49:19 kefren Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -2037,6 +2037,7 @@
 ./usr/share/man/cat5/lastlogx.0			man-sys-catman		.cat
 ./usr/share/man/cat5/ld.so.conf.0		man-sys-catman		.cat
 ./usr/share/man/cat5/ldap_table.0		man-postfix-catman	postfix,.cat
+./usr/share/man/cat5/ldpd.conf.0		man-router-catman	.cat
 ./usr/share/man/cat5/link.0			man-sys-catman		.cat
 ./usr/share/man/cat5/lkm.conf.0			man-obsolete		obsolete
 ./usr/share/man/cat5/locale.alias.0		man-sys-catman		.cat
@@ -4929,6 +4930,7 @@
 ./usr/share/man/html5/lastlogx.html		man-sys-htmlman		html
 ./usr/share/man/html5/ld.so.conf.html		man-sys-htmlman		html
 ./usr/share/man/html5/ldap_table.html		man-postfix-htmlman	postfix,html
+./usr/share/man/html5/ldpd.conf.html		man-router-htmlman	html
 ./usr/share/man/html5/link.html			man-sys-htmlman		html
 ./usr/share/man/html5/lkm.conf.html		man-obsolete		obsolete
 ./usr/share/man/html5/locale.alias.html		man-sys-htmlman		html
@@ -7767,6 +7769,7 @@
 ./usr/share/man/man5/lastlogx.5			man-sys-man		.man
 ./usr/share/man/man5/ld.so.conf.5		man-sys-man		.man
 ./usr/share/man/man5/ldap_table.5		man-postfix-man		postfix,.man
+./usr/share/man/man5/ldpd.conf.5		man-router-man		.man
 ./usr/share/man/man5/link.5			man-sys-man		.man
 ./usr/share/man/man5/lkm.conf.5			man-obsolete		obsolete
 ./usr/share/man/man5/locale.alias.5		man-sys-man		.man

Index: src/usr.sbin/ldpd/Makefile
diff -u src/usr.sbin/ldpd/Makefile:1.4 src/usr.sbin/ldpd/Makefile:1.5
--- src/usr.sbin/ldpd/Makefile:1.4	Mon Nov 12 18:39:00 2012
+++ src/usr.sbin/ldpd/Makefile	Fri Oct 18 10:49:19 2013
@@ -1,9 +1,9 @@
-# $NetBSD: Makefile,v 1.4 2012/11/12 18:39:00 kefren Exp $
+# $NetBSD: Makefile,v 1.5 2013/10/18 10:49:19 kefren Exp $
 
 .include 
 
 PROG=   ldpd
-MAN=ldpd.8
+MAN=ldpd.8 ldpd.conf.5
 
 SRCS=   conffile.c \
 	fsm.c \

Added files:

Index: src/usr.sbin/ldpd/ldpd.conf.5
diff -u /dev/null src/usr.sbin/ldpd/ldpd.conf.5:1.1
--- /dev/null	Fri Oct 18 10:49:19 2013
+++ src/usr.sbin/ldpd/ldpd.conf.5	Fri Oct 18 10:49:19 2013
@@ -0,0 +1,127 @@
+.\"	$NetBSD: ldpd.conf.5,v 1.1 2013/10/18 10:49:19 kefren Exp $
+.\"
+.\" Copyright (c) 2013 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\"notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\"notice, this list of conditions and the following disclaimer in the
+.\"documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd October 18, 2013
+.Dt LDPD.CONF 5
+.Os
+.Sh NAME
+.Nm ldpd.conf
+.Nd ldpd configuration file
+.Sh SYNOPSIS
+.Nm
+.Sh DESCRIPTION
+The
+.Nm
+file defines the
+.Xr ldpd 8
+initial setup and may contain information about LDP identificator, network,
+neighbour and interface parameters.
+Blank lines are allowed and comments lines should start with
+.Sq # .
+Non block lines should end with a semicolon.
+.Sh FILES
+.Bl -tag -width /

CVS commit: src/usr.sbin/ldpd

2013-10-17 Thread Mihai Chelaru
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/

CVS commit: src/usr.sbin/ldpd

2013-10-12 Thread Mihai Chelaru
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/sys/netmpls

2013-08-06 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Wed Aug  7 06:55:00 UTC 2013

Modified Files:
src/sys/netmpls: mpls_ttl.c

Log Message:
reserve space for ICMP header accordingly to RFC4884


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/netmpls/mpls_ttl.c

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

Modified files:

Index: src/sys/netmpls/mpls_ttl.c
diff -u src/sys/netmpls/mpls_ttl.c:1.3 src/sys/netmpls/mpls_ttl.c:1.4
--- src/sys/netmpls/mpls_ttl.c:1.3	Mon Jul  5 09:54:26 2010
+++ src/sys/netmpls/mpls_ttl.c	Wed Aug  7 06:55:00 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: mpls_ttl.c,v 1.3 2010/07/05 09:54:26 kefren Exp $ */
+/*	$NetBSD: mpls_ttl.c,v 1.4 2013/08/07 06:55:00 kefren Exp $ */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -97,7 +97,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mpls_ttl.c,v 1.3 2010/07/05 09:54:26 kefren Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mpls_ttl.c,v 1.4 2013/08/07 06:55:00 kefren Exp $");
 
 #include "opt_inet.h"
 #include "opt_mpls.h"
@@ -165,8 +165,9 @@ static void mpls_icmp_error(struct mbuf 
 static bool ip4_check(struct mbuf *);
 
 /*
- * Reference: http://tools.ietf.org/html/rfc4950
+ * References: RFC 4884 and RFC 4950
  * This should be in sync with icmp_error() in sys/netinet/ip_icmp.c
+ * XXX: is called only for ICMP_TIMXCEED_INTRANS but code is too general
  */
 
 static void
@@ -238,7 +239,8 @@ mpls_icmp_error(struct mbuf *n, int type
 		mblen += m->m_len;
 	icmplen = min(mblen, icmplen);
 
-	packetlen = sizeof(struct ip) + ICMP_EXT_OFFSET + sizeof(mpls_icmp_ext);
+	packetlen = sizeof(struct ip) + offsetof(struct icmp, icmp_ip) +
+	ICMP_EXT_OFFSET + sizeof(mpls_icmp_ext);
 
 	/*
 	 * As we are not required to return everything we have,
@@ -265,13 +267,12 @@ mpls_icmp_error(struct mbuf *n, int type
 	m->m_len = packetlen;
 	if ((m->m_flags & M_EXT) == 0)
 		MH_ALIGN(m, m->m_len);
-	else {
-		m->m_data += sizeof(struct ip);
-		m->m_len -= sizeof(struct ip);
-	}
+	m->m_data += sizeof(struct ip);
+	m->m_len -= sizeof(struct ip);
+
 	icp = mtod(m, struct icmp *);
 	if ((u_int)type > ICMP_MAXTYPE)
-		panic("icmp error");
+		panic("icmp error (mpls_ttl)");
 	ICMP_STATINC(ICMP_STAT_OUTHIST + type);
 	icp->icmp_type = type;
 	if (type == ICMP_REDIRECT)
@@ -377,8 +378,8 @@ mpls_ttl_dec(struct mbuf *m)
 	union mpls_shim top_shim, bossh;
 #endif
 
-	if (m->m_len < sizeof(union mpls_shim) &&
-	(m = m_pullup(m, sizeof(union mpls_shim))) == NULL)
+	if (__predict_false(m->m_len < sizeof(union mpls_shim) &&
+	(m = m_pullup(m, sizeof(union mpls_shim))) == NULL))
 		return NULL;
 	mshim = mtod(m, union mpls_shim *);
 	mshim->s_addr = ntohl(mshim->s_addr);



CVS commit: src/usr.sbin/ldpd

2013-08-02 Thread Mihai Chelaru
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 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -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

CVS commit: src/usr.sbin/ldpd

2013-07-30 Thread Mihai Chelaru
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 
 
 #include 
+#include 
 #include 
 #include 
 
@@ -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;
 
-	SLIS

CVS commit: src/tests/net/mpls

2013-07-27 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Sat Jul 27 14:39:24 UTC 2013

Modified Files:
src/tests/net/mpls: t_ldp_static.sh

Log Message:
Disable ip forwarding at penultimate hop
Raise the ping wait time a little bit in order for changes to propagate
over ldp


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/net/mpls/t_ldp_static.sh

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

Modified files:

Index: src/tests/net/mpls/t_ldp_static.sh
diff -u src/tests/net/mpls/t_ldp_static.sh:1.1 src/tests/net/mpls/t_ldp_static.sh:1.2
--- src/tests/net/mpls/t_ldp_static.sh:1.1	Thu Jul 25 14:28:29 2013
+++ src/tests/net/mpls/t_ldp_static.sh	Sat Jul 27 14:39:24 2013
@@ -1,4 +1,4 @@
-# $NetBSD: t_ldp_static.sh,v 1.1 2013/07/25 14:28:29 kefren Exp $
+# $NetBSD: t_ldp_static.sh,v 1.2 2013/07/27 14:39:24 kefren Exp $
 #
 # Copyright (c) 2013 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -86,7 +86,7 @@ ping_one() {
 	# to R4's ldpd. ldpd on R4 should verify that the next hop
 	# corresponds to its routing table and tag the route to an
 	RUMP_SERVER=${RUMP_SERVER1} atf_check -s exit:0 -o ignore -e ignore \
-		rump.ping -n -o -w 2 $1
+		rump.ping -n -o -w 5 $1
 
 	# Tear it down and bye bye
 	RUMP_SERVER=${RUMP_SERVER5} atf_check -s exit:0 \
@@ -161,6 +161,7 @@ create_servers() {
 	atf_check -s exit:0 rump.ifconfig shmif1 10.0.4.1/24
 	atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1
 	atf_check -s exit:0 rump.sysctl -q -w net.mpls.forwarding=1
+	atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=0
 	atf_check -s exit:0 rump.ifconfig mpls0 create up
 	atf_check -s exit:0 rump.route -q add 10.0.1.0/24 10.0.3.1
 	atf_check -s exit:0 rump.route -q add 10.0.5.0/24 10.0.4.2



CVS commit: src/tests/net/mpls

2013-07-27 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Sat Jul 27 14:36:39 UTC 2013

Modified Files:
src/tests/net/mpls: t_ldp_regen.sh

Log Message:
don't expect failure anymore


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/net/mpls/t_ldp_regen.sh

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

Modified files:

Index: src/tests/net/mpls/t_ldp_regen.sh
diff -u src/tests/net/mpls/t_ldp_regen.sh:1.1 src/tests/net/mpls/t_ldp_regen.sh:1.2
--- src/tests/net/mpls/t_ldp_regen.sh:1.1	Thu Jul 25 14:28:29 2013
+++ src/tests/net/mpls/t_ldp_regen.sh	Sat Jul 27 14:36:39 2013
@@ -1,4 +1,4 @@
-# $NetBSD: t_ldp_regen.sh,v 1.1 2013/07/25 14:28:29 kefren Exp $
+# $NetBSD: t_ldp_regen.sh,v 1.2 2013/07/27 14:36:39 kefren Exp $
 #
 # Copyright (c) 2013 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -61,8 +61,6 @@ newaddr_and_ping() {
 	# Now ldpd on R5 should take notice of the new route and announce it
 	# to R4's ldpd. ldpd on R4 should verify that the next hop
 	# corresponds to its routing table and change its tag entry
-
-	atf_expect_fail "IMPLNULL label bindings are not upgraded properly"
 	RUMP_SERVER=${RUMP_SERVER1} atf_check -s exit:0 -o ignore -e ignore \
 		rump.ping -n -o -w 5 10.0.5.1
 }



CVS commit: src/usr.sbin/ldpd

2013-07-27 Thread Mihai Chelaru
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

2013-07-25 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Thu Jul 25 14:28:29 UTC 2013

Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/net/mpls: Makefile
Added Files:
src/tests/net/mpls: t_ldp_regen.sh t_ldp_static.sh

Log Message:
add a couple of tests for dynamic MPLS routes generation using ldpd


To generate a diff of this commit:
cvs rdiff -u -r1.541 -r1.542 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.2 -r1.3 src/tests/net/mpls/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/net/mpls/t_ldp_regen.sh \
src/tests/net/mpls/t_ldp_static.sh

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

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.541 src/distrib/sets/lists/tests/mi:1.542
--- src/distrib/sets/lists/tests/mi:1.541	Tue Jul 23 11:26:33 2013
+++ src/distrib/sets/lists/tests/mi	Thu Jul 25 14:28:29 2013
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.541 2013/07/23 11:26:33 kefren Exp $
+# $NetBSD: mi,v 1.542 2013/07/25 14:28:29 kefren Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -2600,6 +2600,8 @@
 ./usr/tests/net/mplstests-net-tests
 ./usr/tests/net/mpls/Atffile			tests-net-tests		atf,rump
 ./usr/tests/net/mpls/Kyuafile			tests-net-tests		atf,rump,kyua
+./usr/tests/net/mpls/t_ldp_regen		tests-net-tests		atf,rump
+./usr/tests/net/mpls/t_ldp_static		tests-net-tests		atf,rump
 ./usr/tests/net/mpls/t_mpls_fw			tests-net-tests		atf,rump
 ./usr/tests/net/mpls/t_rfc4182			tests-net-tests		atf,rump
 ./usr/tests/net/nettests-net-tests

Index: src/tests/net/mpls/Makefile
diff -u src/tests/net/mpls/Makefile:1.2 src/tests/net/mpls/Makefile:1.3
--- src/tests/net/mpls/Makefile:1.2	Tue Jul 23 11:26:33 2013
+++ src/tests/net/mpls/Makefile	Thu Jul 25 14:28:29 2013
@@ -1,10 +1,10 @@
-# $NetBSD: Makefile,v 1.2 2013/07/23 11:26:33 kefren Exp $
+# $NetBSD: Makefile,v 1.3 2013/07/25 14:28:29 kefren Exp $
 #
 
 .include 
 
 TESTSDIR=	${TESTSBASE}/net/mpls
 
-TESTS_SH=	t_mpls_fw t_rfc4182
+TESTS_SH=	t_mpls_fw t_rfc4182 t_ldp_regen t_ldp_static
 
 .include 

Added files:

Index: src/tests/net/mpls/t_ldp_regen.sh
diff -u /dev/null src/tests/net/mpls/t_ldp_regen.sh:1.1
--- /dev/null	Thu Jul 25 14:28:29 2013
+++ src/tests/net/mpls/t_ldp_regen.sh	Thu Jul 25 14:28:29 2013
@@ -0,0 +1,176 @@
+# $NetBSD: t_ldp_regen.sh,v 1.1 2013/07/25 14:28:29 kefren Exp $
+#
+# Copyright (c) 2013 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#notice, this list of conditions and the following disclaimer in the
+#documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+# IP/MPLS & LDP label reallocation test
+# Create 4 routers connected like this: R1--R2--R3--R4--
+# The goal is to push packets from R1 to the R4 shmif1 (the right one) interface
+# Enable MPLS forwarding on R2
+# Disable IP forwarding and enable MPLS forwarding on R3
+# Start ldpd and wait for adjancencies to come up
+# Add an alias on shmif1 on R4 for which we already have a route on R3
+# Now: * R4 should install label IMPLNULL for that prefix
+#  * R3 should realloc the target label from IMPLNULL to something else
+
+
+RUMP_SERVER1=unix://./r1
+RUMP_SERVER2=unix://./r2
+RUMP_SERVER3=unix://./r3
+RUMP_SERVER4=unix://./r4
+
+RUMP_LIBS="-lrumpnet -lrumpnet_net -lrumpnet_netmpls -lrumpnet_netinet -lrumpnet_shmif"
+LDP_FLAGS=""
+
+atf_test_case ldp_regen cleanup
+ldp_regen_head() {
+
+	atf_set "descr" "IP/MPLS and LDP label regeneration test"
+	atf_set "require.progs" "rump_server"
+	atf_set "use.fs" "true"
+}
+
+newaddr_and_ping() {
+
+	# Add new address on R4
+	RUMP_SERVER=${RUMP_SERVER4} atf_check -s exit:0 \
+		rump.ifconfig shmif1 10.0.5.1/24 alias
+
+	# Now ldpd on R5 should take notice of the new route and announce it
+	

CVS commit: src/usr.sbin/ldpd

2013-07-25 Thread Mihai Chelaru
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/sys/net

2013-07-24 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Wed Jul 24 15:31:04 UTC 2013

Modified Files:
src/sys/net: rtsock.c

Log Message:
report about route tag in sysctl route walker


To generate a diff of this commit:
cvs rdiff -u -r1.141 -r1.142 src/sys/net/rtsock.c

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

Modified files:

Index: src/sys/net/rtsock.c
diff -u src/sys/net/rtsock.c:1.141 src/sys/net/rtsock.c:1.142
--- src/sys/net/rtsock.c:1.141	Fri Mar  1 18:25:57 2013
+++ src/sys/net/rtsock.c	Wed Jul 24 15:31:04 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtsock.c,v 1.141 2013/03/01 18:25:57 joerg Exp $	*/
+/*	$NetBSD: rtsock.c,v 1.142 2013/07/24 15:31:04 kefren Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.141 2013/03/01 18:25:57 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.142 2013/07/24 15:31:04 kefren Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1029,6 +1029,7 @@ sysctl_dumpentry(struct rtentry *rt, voi
 	info.rti_info[RTAX_DST] = rt_getkey(rt);
 	info.rti_info[RTAX_GATEWAY] = rt->rt_gateway;
 	info.rti_info[RTAX_NETMASK] = rt_mask(rt);
+	info.rti_info[RTAX_TAG] = rt_gettag(rt);
 	if (rt->rt_ifp) {
 		const struct ifaddr *rtifa;
 		info.rti_info[RTAX_IFP] = rt->rt_ifp->if_dl->ifa_addr;



CVS commit: src/usr.sbin/ldpd

2013-07-24 Thread Mihai Chelaru
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_

CVS commit: src/share/man/man4

2013-07-23 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Wed Jul 24 06:31:09 UTC 2013

Modified Files:
src/share/man/man4: mpls.4

Log Message:
EXP -> TC
document RFC4182 sysctl flag
document a little bit more the IMPLNULL operation


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/share/man/man4/mpls.4

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

Modified files:

Index: src/share/man/man4/mpls.4
diff -u src/share/man/man4/mpls.4:1.7 src/share/man/man4/mpls.4:1.8
--- src/share/man/man4/mpls.4:1.7	Sun Jul 17 23:50:05 2011
+++ src/share/man/man4/mpls.4	Wed Jul 24 06:31:09 2013
@@ -1,4 +1,4 @@
-.\" $NetBSD: mpls.4,v 1.7 2011/07/17 23:50:05 dholland Exp $
+.\" $NetBSD: mpls.4,v 1.8 2013/07/24 06:31:09 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 June 29, 2010
+.Dd July 24, 2013
 .Dt MPLS 4
 .Os
 .Sh NAME
@@ -70,7 +70,7 @@ In network bit order:
 .Bd -literal
 ---
 |   ||   ||
-| Label | Exp.   | BoS   | TTL|
+| Label | TC | BoS   | TTL|
 | 20 bits   | 3 bits | 1 bit | 8 bits |
 |   ||   ||
 ---
@@ -79,13 +79,16 @@ In network bit order:
 .It Label
 20 bits representing FEC, consequently the only information
 used to forward the frame to next-hop
-.It Experimental
-3 bits that are sometimes used for specifying a type of service
+.It Traffic Class Field
+3 bits that are used for specifying a traffic class, usually used for defining
+a type of service.
+This field was named the "Experimental Field" in most early (pre-
+.%R RFC 5462
+) documents.
 .It Bottom of Stack
-1 bit that is set for the last entry in the shim
-stack and 0 for all others.
-This way, multiple labels can
-be prepended to a single packet.
+One bit that is set for the last entry in the shim stack and 0 for all others.
+An MPLS frame may contain more than one shim, the last one before the
+network headers being marked by setting the BoS bit.
 .It TTL
 8 bits, representing Time to Live, decremented at every LSR.
 .El
@@ -109,20 +112,22 @@ will be copied into IP header on decapsu
 The IPv6 version of the above.
 .It Li net.mpls.inet_map_prec
 If set, precedence field from IP header will be
-mapped into MPLS shim EXP bits on encapsulation, and the MPLS EXP
+mapped into MPLS shim in TC field on encapsulation, and the MPLS TC
 field will be copied into IP Precedence field on decapsulation.
 .It Li net.mpls.inet6_map_prec
 The IPv6 version of the above.
 .It Li net.mpls.icmp_respond
 Returns ICMP TTL exceeded in transit when an MPLS
 frame is dropped because of TTL = 0 on egress interface.
+.It Li net.mpls.rfc4182
+Pop the Explicit Null labels as specified by
+.%R RFC 4182
 .El
 In order to encapsulate and decapsulate to and from MPLS, an mpls
 pseudo-interface must be created and packets that should be encapsulated
 must be routed to that interface.
 .Pp
-.Dq Pure
-MPLS routes can be created using
+MPLS routes may be created using
 .Dv AF_MPLS
 .Li sa_family
 sockaddrs for destination and tag fields.
@@ -143,6 +148,14 @@ and
 .Xr route 8
 utilities should be used to manage routes from userland.
 .Pp
+The
+.Nx
+implementation stores route tagging information into a sockaddr_mpls structure
+that is referenced by the rt_tag field of rtentry struct.
+For storing multiple labels associated with the next-hop, the current
+implementation abuses the sockaddr_mpls structure, extending it in order to fit
+a stack of labels.
+.Pp
 .Xr ldpd 8
 should be used in order to automatically import, manage and
 distribute labels among LSRs in the same MPLS domain.
@@ -171,6 +184,13 @@ When an LSR would otherwise replace the 
 with a new label, but the new label is
 .Dq Implicit NULL ,
 the LSR will pop the stack instead of doing the replacement.
+In this case, the LSR will have to deduce by itself what is the original
+address family of the encapsulated network packet.
+Currently,
+.Nx
+implementation is assuming that the latter address family
+is equal to the next-hop address family specified in the Implicit Null Label
+MPLS route.
 .El
 .Sh EXAMPLES
 .Bl -enum
@@ -245,6 +265,14 @@ and forward the result to 192.168.1.100
 .%R RFC 3032
 .%T MPLS Label Stack Encoding
 .Re
+.Rs
+.%R RFC 4182
+.%T Removing a Restriction on the use of MPLS Explicit NULL
+.Re
+.Rs
+.%R RFC 5462
+.%T MPLS Label Stack Entry: "EXP" Field Renamed to "Traffic Class" Field
+.Re
 .Sh HISTORY
 The
 .Nm



CVS commit: src/sbin/route

2013-07-23 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Wed Jul 24 06:28:10 UTC 2013

Modified Files:
src/sbin/route: route.8

Log Message:
Add -tag description as suggested in PR/45071


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/sbin/route/route.8

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

Modified files:

Index: src/sbin/route/route.8
diff -u src/sbin/route/route.8:1.47 src/sbin/route/route.8:1.48
--- src/sbin/route/route.8:1.47	Fri Mar  1 18:25:17 2013
+++ src/sbin/route/route.8	Wed Jul 24 06:28:10 2013
@@ -1,4 +1,4 @@
-.\"	$NetBSD: route.8,v 1.47 2013/03/01 18:25:17 joerg Exp $
+.\"	$NetBSD: route.8,v 1.48 2013/07/24 06:28:10 kefren Exp $
 .\"
 .\" Copyright (c) 1983, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\" @(#)route.8	8.4 (Berkeley) 6/1/94
 .\"
-.Dd February 5, 2013
+.Dd July 24, 2013
 .Dt ROUTE 8
 .Os
 .Sh NAME
@@ -242,11 +242,16 @@ or are specified as link-level addresses
 and the names must be numeric specifications rather than
 symbolic names.
 .Pp
-The optional modifiers
-.Fl mpls
-and
+The optional modifier
 .Fl tag
-specify that all subsequent addresses are in the
+specifies an address associated to the route.
+How the address is used is specific to the address family of
+the destination and the interface used to forward the packet.
+Currently route tags are consumed only by the
+.Xr mpls 4
+stack, therefore
+.Nm
+assumes that the subsequent addresses are in the
 .Tn MPLS
 address family.
 See



CVS commit: src/tests/net/mpls

2013-07-23 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Tue Jul 23 12:41:01 UTC 2013

Modified Files:
src/tests/net/mpls: t_mpls_fw.sh t_rfc4182.sh

Log Message:
Use . for shm bus path and rump_server url instead of /tmp
Exit after first reply in mpls_fw


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/net/mpls/t_mpls_fw.sh
cvs rdiff -u -r1.1 -r1.2 src/tests/net/mpls/t_rfc4182.sh

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

Modified files:

Index: src/tests/net/mpls/t_mpls_fw.sh
diff -u src/tests/net/mpls/t_mpls_fw.sh:1.2 src/tests/net/mpls/t_mpls_fw.sh:1.3
--- src/tests/net/mpls/t_mpls_fw.sh:1.2	Tue Jul 23 12:14:49 2013
+++ src/tests/net/mpls/t_mpls_fw.sh	Tue Jul 23 12:41:01 2013
@@ -1,4 +1,4 @@
-# $NetBSD: t_mpls_fw.sh,v 1.2 2013/07/23 12:14:49 martin Exp $
+# $NetBSD: t_mpls_fw.sh,v 1.3 2013/07/23 12:41:01 kefren Exp $
 #
 # Copyright (c) 2013 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -37,10 +37,10 @@
 # ping from R1 to R4 right hand side interface
 
 
-RUMP_SERVER1=unix:///tmp/r1
-RUMP_SERVER2=unix:///tmp/r2
-RUMP_SERVER3=unix:///tmp/r3
-RUMP_SERVER4=unix:///tmp/r4
+RUMP_SERVER1=unix://./r1
+RUMP_SERVER2=unix://./r2
+RUMP_SERVER3=unix://./r3
+RUMP_SERVER4=unix://./r4
 
 RUMP_FLAGS=\
 "-lrumpnet -lrumpnet_net -lrumpnet_netmpls -lrumpnet_netinet -lrumpnet_shmif"
@@ -129,7 +129,7 @@ doping()
 
 	export RUMP_SERVER=${RUMP_SERVER1}
 	atf_check -s exit:0 -o match:"64 bytes from 10.0.4.1: icmp_seq=" \
-	rump.ping -n -w 5 10.0.4.1
+	rump.ping -n -o -w 5 10.0.4.1
 	unset RUMP_SERVER
 }
 

Index: src/tests/net/mpls/t_rfc4182.sh
diff -u src/tests/net/mpls/t_rfc4182.sh:1.1 src/tests/net/mpls/t_rfc4182.sh:1.2
--- src/tests/net/mpls/t_rfc4182.sh:1.1	Tue Jul 23 11:26:33 2013
+++ src/tests/net/mpls/t_rfc4182.sh	Tue Jul 23 12:41:01 2013
@@ -1,4 +1,4 @@
-# $NetBSD: t_rfc4182.sh,v 1.1 2013/07/23 11:26:33 kefren Exp $
+# $NetBSD: t_rfc4182.sh,v 1.2 2013/07/23 12:41:01 kefren Exp $
 #
 # Copyright (c) 2013 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -39,10 +39,10 @@
 # ping from R1 to R4 right hand side interface
 
 
-RUMP_SERVER1=unix:///tmp/r1
-RUMP_SERVER2=unix:///tmp/r2
-RUMP_SERVER3=unix:///tmp/r3
-RUMP_SERVER4=unix:///tmp/r4
+RUMP_SERVER1=unix://./r1
+RUMP_SERVER2=unix://./r2
+RUMP_SERVER3=unix://./r3
+RUMP_SERVER4=unix://./r4
 
 RUMP_FLAGS=\
 "-lrumpnet -lrumpnet_net -lrumpnet_netmpls -lrumpnet_netinet -lrumpnet_shmif"
@@ -71,7 +71,7 @@ configservers()
 	# Setup the first server
 	export RUMP_SERVER=${RUMP_SERVER1}
 	atf_check -s exit:0 rump.ifconfig shmif0 create
-	atf_check -s exit:0 rump.ifconfig shmif0 linkstr /tmp/shdom1
+	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom1
 	atf_check -s exit:0 rump.ifconfig shmif0 10.0.1.1/24
 	atf_check -s exit:0 rump.ifconfig mpls0 create up
 	atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1
@@ -82,10 +82,10 @@ configservers()
 	# Setup the second server
 	export RUMP_SERVER=${RUMP_SERVER2}
 	atf_check -s exit:0 rump.ifconfig shmif0 create
-	atf_check -s exit:0 rump.ifconfig shmif0 linkstr /tmp/shdom1
+	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom1
 	atf_check -s exit:0 rump.ifconfig shmif0 10.0.1.2/24
 	atf_check -s exit:0 rump.ifconfig shmif1 create
-	atf_check -s exit:0 rump.ifconfig shmif1 linkstr /tmp/shdom2
+	atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom2
 	atf_check -s exit:0 rump.ifconfig shmif1 10.0.2.1/24
 	atf_check -s exit:0 rump.ifconfig mpls0 create up
 	atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1
@@ -97,10 +97,10 @@ configservers()
 	# Setup the third server
 	export RUMP_SERVER=${RUMP_SERVER3}
 	atf_check -s exit:0 rump.ifconfig shmif0 create
-	atf_check -s exit:0 rump.ifconfig shmif0 linkstr /tmp/shdom2
+	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom2
 	atf_check -s exit:0 rump.ifconfig shmif0 10.0.2.2/24
 	atf_check -s exit:0 rump.ifconfig shmif1 create
-	atf_check -s exit:0 rump.ifconfig shmif1 linkstr /tmp/shdom3
+	atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom3
 	atf_check -s exit:0 rump.ifconfig shmif1 10.0.3.1/24
 	atf_check -s exit:0 rump.ifconfig mpls0 create up
 	atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1
@@ -112,10 +112,10 @@ configservers()
 	# Setup the fourth server
 	export RUMP_SERVER=${RUMP_SERVER4}
 	atf_check -s exit:0 rump.ifconfig shmif0 create
-	atf_check -s exit:0 rump.ifconfig shmif0 linkstr /tmp/shdom3
+	atf_check -s exit:0 rump.ifconfig shmif0 linkstr ./shdom3
 	atf_check -s exit:0 rump.ifconfig shmif0 10.0.3.2/24
 	atf_check -s exit:0 rump.ifconfig shmif1 create
-	atf_check -s exit:0 rump.ifconfig shmif1 linkstr /tmp/shdom4
+	atf_check -s exit:0 rump.ifconfig shmif1 linkstr ./shdom4
 	atf_check -s exit:0 rump.ifconfig shmif1 10.0.4.1/24
 	atf_check -s exit:0 rump.ifconfig mpls0 create up
 	atf_check -s exit:0 rump.sysctl -q -w net.mpls.accept=1



CVS commit: src

2013-07-23 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Tue Jul 23 11:26:33 UTC 2013

Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/net/mpls: Makefile
Added Files:
src/tests/net/mpls: t_rfc4182.sh

Log Message:
Add a test for RFC4182


To generate a diff of this commit:
cvs rdiff -u -r1.540 -r1.541 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.1 -r1.2 src/tests/net/mpls/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/net/mpls/t_rfc4182.sh

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

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.540 src/distrib/sets/lists/tests/mi:1.541
--- src/distrib/sets/lists/tests/mi:1.540	Fri Jul 19 04:00:40 2013
+++ src/distrib/sets/lists/tests/mi	Tue Jul 23 11:26:33 2013
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.540 2013/07/19 04:00:40 kefren Exp $
+# $NetBSD: mi,v 1.541 2013/07/23 11:26:33 kefren Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -2601,6 +2601,7 @@
 ./usr/tests/net/mpls/Atffile			tests-net-tests		atf,rump
 ./usr/tests/net/mpls/Kyuafile			tests-net-tests		atf,rump,kyua
 ./usr/tests/net/mpls/t_mpls_fw			tests-net-tests		atf,rump
+./usr/tests/net/mpls/t_rfc4182			tests-net-tests		atf,rump
 ./usr/tests/net/nettests-net-tests
 ./usr/tests/net/net/Atffile			tests-net-tests		atf
 ./usr/tests/net/net/Kyuafile			tests-net-tests		atf,kyua

Index: src/tests/net/mpls/Makefile
diff -u src/tests/net/mpls/Makefile:1.1 src/tests/net/mpls/Makefile:1.2
--- src/tests/net/mpls/Makefile:1.1	Fri Jul 19 04:00:40 2013
+++ src/tests/net/mpls/Makefile	Tue Jul 23 11:26:33 2013
@@ -1,10 +1,10 @@
-# $NetBSD: Makefile,v 1.1 2013/07/19 04:00:40 kefren Exp $
+# $NetBSD: Makefile,v 1.2 2013/07/23 11:26:33 kefren Exp $
 #
 
 .include 
 
 TESTSDIR=	${TESTSBASE}/net/mpls
 
-TESTS_SH=	t_mpls_fw
+TESTS_SH=	t_mpls_fw t_rfc4182
 
 .include 

Added files:

Index: src/tests/net/mpls/t_rfc4182.sh
diff -u /dev/null src/tests/net/mpls/t_rfc4182.sh:1.1
--- /dev/null	Tue Jul 23 11:26:33 2013
+++ src/tests/net/mpls/t_rfc4182.sh	Tue Jul 23 11:26:33 2013
@@ -0,0 +1,165 @@
+# $NetBSD: t_rfc4182.sh,v 1.1 2013/07/23 11:26:33 kefren Exp $
+#
+# Copyright (c) 2013 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#notice, this list of conditions and the following disclaimer in the
+#documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+# TEST RFC 4182
+# Setup four routers connected like this: R1---R2---R3---R4--
+# Goal is to be able to ping from R1 the outermost interface of R4
+# Disable net.inet.ip.forwarding, enable net.mpls.forwarding
+# Add route on R1 in order to encapsulate into MPLS the IP packets with
+# destination equal to R4 right hand side interface. Use two labels here:
+# 25 and IPv6 Explicit NULL
+# Add a double tagged MPLS route on R2 in order to forward frames belonging to
+# that FEC to R3, with IPv4 NULL being the most outermost one
+# Add MPLS "POP" route on R3 for that FEC, pointing to R4
+# Do the same for the reverse direction (R4 to R1)
+# ping from R1 to R4 right hand side interface
+
+
+RUMP_SERVER1=unix:///tmp/r1
+RUMP_SERVER2=unix:///tmp/r2
+RUMP_SERVER3=unix:///tmp/r3
+RUMP_SERVER4=unix:///tmp/r4
+
+RUMP_FLAGS=\
+"-lrumpnet -lrumpnet_net -lrumpnet_netmpls -lrumpnet_netinet -lrumpnet_shmif"
+
+atf_test_case rfc4182 cleanup
+rfc4182_head()
+{
+
+	atf_set "descr" "RFC 4182 conformance test"
+	atf_set "require.progs" "rump_server"
+}
+
+startservers()
+{
+
+	ulimit -r 300
+	atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${RUMP_SERVER1}
+	atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${RUMP_SERVER2}
+	atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${RUMP_SERVER3}
+	atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${RUMP_SERVER4}

CVS commit: src/sys

2013-07-23 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Tue Jul 23 11:11:55 UTC 2013

Modified Files:
src/sys/net: if_mpls.c
src/sys/netmpls: mpls_proto.c

Log Message:
Implement RFC4182 changes - switchable via sysctl


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/net/if_mpls.c
cvs rdiff -u -r1.4 -r1.5 src/sys/netmpls/mpls_proto.c

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

Modified files:

Index: src/sys/net/if_mpls.c
diff -u src/sys/net/if_mpls.c:1.9 src/sys/net/if_mpls.c:1.10
--- src/sys/net/if_mpls.c:1.9	Mon Jul 15 12:10:34 2013
+++ src/sys/net/if_mpls.c	Tue Jul 23 11:11:55 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_mpls.c,v 1.9 2013/07/15 12:10:34 kefren Exp $ */
+/*	$NetBSD: if_mpls.c,v 1.10 2013/07/23 11:11:55 kefren Exp $ */
 
 /*
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_mpls.c,v 1.9 2013/07/15 12:10:34 kefren Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_mpls.c,v 1.10 2013/07/23 11:11:55 kefren Exp $");
 
 #include "opt_inet.h"
 #include "opt_mpls.h"
@@ -95,7 +95,8 @@ static struct mbuf *mpls_label_inet6(str
 static struct mbuf *mpls_prepend_shim(struct mbuf *, union mpls_shim *);
 
 extern int mpls_defttl, mpls_mapttl_inet, mpls_mapttl_inet6, mpls_icmp_respond,
-	mpls_forwarding, mpls_accept, mpls_mapprec_inet, mpls_mapclass_inet6;
+	mpls_forwarding, mpls_accept, mpls_mapprec_inet, mpls_mapclass_inet6,
+	mpls_rfc4182;
 
 /* ARGSUSED */
 void
@@ -325,6 +326,19 @@ mpls_lse(struct mbuf *m)
 	if ((m = mpls_ttl_dec(m)) == NULL)
 		goto done;
 
+	/* RFC 4182 */
+	if (mpls_rfc4182 != 0)
+		while((dst.smpls_addr.shim.label == MPLS_LABEL_IPV4NULL ||
+		dst.smpls_addr.shim.label == MPLS_LABEL_IPV6NULL) &&
+		__predict_false(dst.smpls_addr.shim.bos == 0)) {
+			m_adj(m, sizeof(union mpls_shim));
+			if (m->m_len < sizeof(union mpls_shim) &&
+			(m = m_pullup(m, sizeof(union mpls_shim))) == NULL)
+goto done;
+			dst.smpls_addr.s_addr =
+			ntohl(mtod(m, union mpls_shim *)->s_addr);
+		}
+
 	if (dst.smpls_addr.shim.label <= MPLS_LABEL_RESMAX) {
 		/* Don't swap reserved labels */
 		switch (dst.smpls_addr.shim.label) {

Index: src/sys/netmpls/mpls_proto.c
diff -u src/sys/netmpls/mpls_proto.c:1.4 src/sys/netmpls/mpls_proto.c:1.5
--- src/sys/netmpls/mpls_proto.c:1.4	Thu Jul 18 06:23:07 2013
+++ src/sys/netmpls/mpls_proto.c	Tue Jul 23 11:11:55 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: mpls_proto.c,v 1.4 2013/07/18 06:23:07 kefren Exp $ */
+/*	$NetBSD: mpls_proto.c,v 1.5 2013/07/23 11:11:55 kefren Exp $ */
 
 /*
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mpls_proto.c,v 1.4 2013/07/18 06:23:07 kefren Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mpls_proto.c,v 1.5 2013/07/23 11:11:55 kefren Exp $");
 
 #include "opt_inet.h"
 #include "opt_mbuftrace.h"
@@ -65,6 +65,7 @@ int mpls_forwarding = 0;
 int mpls_accept = 0;
 int mpls_mapprec_inet = 1;
 int mpls_mapclass_inet6 = 1;
+int mpls_rfc4182 = 1;
 
 void mpls_init(void)
 {
@@ -176,6 +177,12 @@ sysctl_net_mpls_setup(struct sysctllog *
 		   SYSCTL_DESCR("MPLS queue length"),
 		   NULL, 0, &mplsintrq.ifq_maxlen, 0,
 		   CTL_NET, PF_MPLS, CTL_CREATE, CTL_EOL);
+	sysctl_createv(clog, 0, NULL, NULL,
+		   CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+		   CTLTYPE_INT, "rfc4182",
+		   SYSCTL_DESCR("RFC 4182 conformance"),
+		   NULL, 0, &mpls_rfc4182, 0,
+		   CTL_NET, PF_MPLS, CTL_CREATE, CTL_EOL);
 #ifdef INET
 	sysctl_createv(clog, 0, NULL, NULL,
 		   CTLFLAG_PERMANENT|CTLFLAG_READWRITE,



CVS commit: src/usr.sbin/ldpd

2013-07-19 Thread Mihai Chelaru
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 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -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

2013-07-18 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Fri Jul 19 04:00:40 UTC 2013

Modified Files:
src/distrib/sets/lists/tests: mi
src/etc/mtree: NetBSD.dist.tests
src/tests/net: Makefile
Added Files:
src/tests/net/mpls: Makefile t_mpls_fw.sh

Log Message:
Add a couple of basic IP/MPLS forwarding tests


To generate a diff of this commit:
cvs rdiff -u -r1.539 -r1.540 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.96 -r1.97 src/etc/mtree/NetBSD.dist.tests
cvs rdiff -u -r1.14 -r1.15 src/tests/net/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/net/mpls/Makefile \
src/tests/net/mpls/t_mpls_fw.sh

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

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.539 src/distrib/sets/lists/tests/mi:1.540
--- src/distrib/sets/lists/tests/mi:1.539	Wed Jul  3 14:01:29 2013
+++ src/distrib/sets/lists/tests/mi	Fri Jul 19 04:00:40 2013
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.539 2013/07/03 14:01:29 nakayama Exp $
+# $NetBSD: mi,v 1.540 2013/07/19 04:00:40 kefren Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -2597,6 +2597,10 @@
 ./usr/tests/net/if_loop/Atffile			tests-net-tests		atf,rump
 ./usr/tests/net/if_loop/Kyuafile		tests-net-tests		atf,rump,kyua
 ./usr/tests/net/if_loop/t_pr		tests-net-tests		atf,rump
+./usr/tests/net/mplstests-net-tests
+./usr/tests/net/mpls/Atffile			tests-net-tests		atf,rump
+./usr/tests/net/mpls/Kyuafile			tests-net-tests		atf,rump,kyua
+./usr/tests/net/mpls/t_mpls_fw			tests-net-tests		atf,rump
 ./usr/tests/net/nettests-net-tests
 ./usr/tests/net/net/Atffile			tests-net-tests		atf
 ./usr/tests/net/net/Kyuafile			tests-net-tests		atf,kyua

Index: src/etc/mtree/NetBSD.dist.tests
diff -u src/etc/mtree/NetBSD.dist.tests:1.96 src/etc/mtree/NetBSD.dist.tests:1.97
--- src/etc/mtree/NetBSD.dist.tests:1.96	Thu Mar 21 19:17:51 2013
+++ src/etc/mtree/NetBSD.dist.tests	Fri Jul 19 04:00:40 2013
@@ -1,4 +1,4 @@
-#	$NetBSD: NetBSD.dist.tests,v 1.96 2013/03/21 19:17:51 christos Exp $
+#	$NetBSD: NetBSD.dist.tests,v 1.97 2013/07/19 04:00:40 kefren Exp $
 
 ./usr/libdata/debug/usr/tests
 ./usr/libdata/debug/usr/tests/atf
@@ -302,6 +302,7 @@
 ./usr/tests/net/icmp
 ./usr/tests/net/if
 ./usr/tests/net/if_loop
+./usr/tests/net/mpls
 ./usr/tests/net/net
 ./usr/tests/net/npf
 ./usr/tests/net/route

Index: src/tests/net/Makefile
diff -u src/tests/net/Makefile:1.14 src/tests/net/Makefile:1.15
--- src/tests/net/Makefile:1.14	Wed Jul  3 14:01:29 2013
+++ src/tests/net/Makefile	Fri Jul 19 04:00:40 2013
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.14 2013/07/03 14:01:29 nakayama Exp $
+# $NetBSD: Makefile,v 1.15 2013/07/19 04:00:40 kefren Exp $
 
 .include 
 
@@ -6,7 +6,7 @@ TESTSDIR=	${TESTSBASE}/net
 
 TESTS_SUBDIRS=		fdpass net route sys
 .if (${MKRUMP} != "no")
-TESTS_SUBDIRS+=		bpf bpfilter carp icmp if if_loop npf
+TESTS_SUBDIRS+=		bpf bpfilter carp icmp if if_loop mpls npf
 .endif
 
 .include 

Added files:

Index: src/tests/net/mpls/Makefile
diff -u /dev/null src/tests/net/mpls/Makefile:1.1
--- /dev/null	Fri Jul 19 04:00:40 2013
+++ src/tests/net/mpls/Makefile	Fri Jul 19 04:00:40 2013
@@ -0,0 +1,10 @@
+# $NetBSD: Makefile,v 1.1 2013/07/19 04:00:40 kefren Exp $
+#
+
+.include 
+
+TESTSDIR=	${TESTSBASE}/net/mpls
+
+TESTS_SH=	t_mpls_fw
+
+.include 
Index: src/tests/net/mpls/t_mpls_fw.sh
diff -u /dev/null src/tests/net/mpls/t_mpls_fw.sh:1.1
--- /dev/null	Fri Jul 19 04:00:40 2013
+++ src/tests/net/mpls/t_mpls_fw.sh	Fri Jul 19 04:00:40 2013
@@ -0,0 +1,188 @@
+# $NetBSD: t_mpls_fw.sh,v 1.1 2013/07/19 04:00:40 kefren Exp $
+#
+# Copyright (c) 2013 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#notice, this list of conditions and the following disclaimer in the
+#documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY O

CVS commit: src/distrib/sets/lists

2013-07-18 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Thu Jul 18 16:01:41 UTC 2013

Modified Files:
src/distrib/sets/lists/base: shl.mi
src/distrib/sets/lists/comp: mi shl.mi

Log Message:
Add librumpnet_netmpls into sets' lists


To generate a diff of this commit:
cvs rdiff -u -r1.665 -r1.666 src/distrib/sets/lists/base/shl.mi
cvs rdiff -u -r1.1828 -r1.1829 src/distrib/sets/lists/comp/mi
cvs rdiff -u -r1.249 -r1.250 src/distrib/sets/lists/comp/shl.mi

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

Modified files:

Index: src/distrib/sets/lists/base/shl.mi
diff -u src/distrib/sets/lists/base/shl.mi:1.665 src/distrib/sets/lists/base/shl.mi:1.666
--- src/distrib/sets/lists/base/shl.mi:1.665	Sun Apr 28 04:05:38 2013
+++ src/distrib/sets/lists/base/shl.mi	Thu Jul 18 16:01:41 2013
@@ -1,4 +1,4 @@
-# $NetBSD: shl.mi,v 1.665 2013/04/28 04:05:38 joerg Exp $
+# $NetBSD: shl.mi,v 1.666 2013/07/18 16:01:41 kefren Exp $
 #
 # Note:	Don't delete entries from here - mark them as "obsolete" instead,
 #	unless otherwise stated below.
@@ -660,6 +660,9 @@
 ./usr/lib/librumpnet_netinet.so			base-rump-shlib	rump
 ./usr/lib/librumpnet_netinet.so.0		base-rump-shlib	rump
 ./usr/lib/librumpnet_netinet.so.0.0		base-rump-shlib	rump
+./usr/lib/librumpnet_netmpls.so			base-rump-shlib	rump
+./usr/lib/librumpnet_netmpls.so.0		base-rump-shlib	rump
+./usr/lib/librumpnet_netmpls.so.0.0		base-rump-shlib	rump
 ./usr/lib/librumpnet_shmif.so			base-rump-shlib	rump
 ./usr/lib/librumpnet_shmif.so.0			base-rump-shlib	rump
 ./usr/lib/librumpnet_shmif.so.0.0		base-rump-shlib	rump

Index: src/distrib/sets/lists/comp/mi
diff -u src/distrib/sets/lists/comp/mi:1.1828 src/distrib/sets/lists/comp/mi:1.1829
--- src/distrib/sets/lists/comp/mi:1.1828	Wed Jun 26 12:07:21 2013
+++ src/distrib/sets/lists/comp/mi	Thu Jul 18 16:01:41 2013
@@ -1,4 +1,4 @@
-#	$NetBSD: mi,v 1.1828 2013/06/26 12:07:21 njoly Exp $
+#	$NetBSD: mi,v 1.1829 2013/07/18 16:01:41 kefren Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -3235,6 +3235,8 @@
 ./usr/lib/librumpnet_netbt_p.a			comp-c-proflib		profile,rump
 ./usr/lib/librumpnet_netinet.a			comp-c-lib		rump
 ./usr/lib/librumpnet_netinet_p.a		comp-c-proflib		profile,rump
+./usr/lib/librumpnet_netmpls.a			comp-c-lib		rump
+./usr/lib/librumpnet_netmpls_p.a		comp-c-proflib		profile,rump
 ./usr/lib/librumpnet_npf.a			comp-c-lib		rump
 ./usr/lib/librumpnet_npf_p.a 			comp-c-lib		profile,rump
 ./usr/lib/librumpnet_p.a			comp-c-proflib		profile,rump

Index: src/distrib/sets/lists/comp/shl.mi
diff -u src/distrib/sets/lists/comp/shl.mi:1.249 src/distrib/sets/lists/comp/shl.mi:1.250
--- src/distrib/sets/lists/comp/shl.mi:1.249	Sun Apr 28 04:05:40 2013
+++ src/distrib/sets/lists/comp/shl.mi	Thu Jul 18 16:01:41 2013
@@ -1,4 +1,4 @@
-# $NetBSD: shl.mi,v 1.249 2013/04/28 04:05:40 joerg Exp $
+# $NetBSD: shl.mi,v 1.250 2013/07/18 16:01:41 kefren Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -203,6 +203,7 @@
 ./usr/lib/librumpnet_net_pic.a			comp-c-piclib		rump
 ./usr/lib/librumpnet_netbt_pic.a		comp-c-piclib		rump
 ./usr/lib/librumpnet_netinet_pic.a		comp-c-piclib		rump
+./usr/lib/librumpnet_netmpls_pic.a		comp-c-piclib		rump
 ./usr/lib/librumpnet_npf.so			comp-c-piclib		rump
 ./usr/lib/librumpnet_npf.so.0			comp-c-piclib		rump
 ./usr/lib/librumpnet_npf.so.0.0			comp-c-piclib		rump



CVS commit: src/sys/rump

2013-07-18 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Thu Jul 18 15:59:28 UTC 2013

Modified Files:
src/sys/rump/librump/rumpnet: netisr.c
src/sys/rump/net: Makefile.rumpnetcomp
src/sys/rump/net/lib/libnet: Makefile
src/sys/rump/net/lib/libnet/opt: opt_mpls.h
Added Files:
src/sys/rump/net/lib/libnetmpls: Makefile Makefile.inc component.c
shlib_version

Log Message:
Add librumpnet_netmpls that provides MPLS features into rump kernels
ok'ed pooka@


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/rump/librump/rumpnet/netisr.c
cvs rdiff -u -r1.5 -r1.6 src/sys/rump/net/Makefile.rumpnetcomp
cvs rdiff -u -r1.17 -r1.18 src/sys/rump/net/lib/libnet/Makefile
cvs rdiff -u -r1.1 -r1.2 src/sys/rump/net/lib/libnet/opt/opt_mpls.h
cvs rdiff -u -r0 -r1.1 src/sys/rump/net/lib/libnetmpls/Makefile \
src/sys/rump/net/lib/libnetmpls/Makefile.inc \
src/sys/rump/net/lib/libnetmpls/component.c \
src/sys/rump/net/lib/libnetmpls/shlib_version

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

Modified files:

Index: src/sys/rump/librump/rumpnet/netisr.c
diff -u src/sys/rump/librump/rumpnet/netisr.c:1.5 src/sys/rump/librump/rumpnet/netisr.c:1.6
--- src/sys/rump/librump/rumpnet/netisr.c:1.5	Thu Dec 30 16:19:39 2010
+++ src/sys/rump/librump/rumpnet/netisr.c	Thu Jul 18 15:59:27 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: netisr.c,v 1.5 2010/12/30 16:19:39 pooka Exp $	*/
+/*	$NetBSD: netisr.c,v 1.6 2013/07/18 15:59:27 kefren Exp $	*/
 
 /*
  * Copyright (c) 2008 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: netisr.c,v 1.5 2010/12/30 16:19:39 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netisr.c,v 1.6 2013/07/18 15:59:27 kefren Exp $");
 
 #include 
 #include 
@@ -36,6 +36,7 @@ __KERNEL_RCSID(0, "$NetBSD: netisr.c,v 1
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -63,11 +64,12 @@ __netisr_stub(void)
 __weak_alias(ipintr,__netisr_stub);
 __weak_alias(arpintr,__netisr_stub);
 __weak_alias(ip6intr,__netisr_stub);
+__weak_alias(mplsintr,__netisr_stub);
 
 void
 rump_netisr_init(void)
 {
-	void *iphand, *arphand, *ip6hand, *sym;
+	void *iphand, *arphand, *ip6hand, *mplshand, *sym;
 
 	iphand = ipintr;
 	if ((sym = rumpuser_dl_globalsym("rumpns_ipintr")) != NULL)
@@ -80,6 +82,10 @@ rump_netisr_init(void)
 	ip6hand = ip6intr;
 	if ((sym = rumpuser_dl_globalsym("rumpns_ip6intr")) != NULL)
 		ip6hand = sym;
+
+	mplshand = mplsintr;
+	if ((sym = rumpuser_dl_globalsym("rumpns_mplsintr")) != NULL)
+		mplshand = sym;
 		
 	netisrs[NETISR_IP] = softint_establish(SOFTINT_NET | SOFTINT_MPSAFE,
 	(void (*)(void *))iphand, NULL);
@@ -87,4 +93,6 @@ rump_netisr_init(void)
 	(void (*)(void *))arphand, NULL);
 	netisrs[NETISR_IPV6] = softint_establish(SOFTINT_NET | SOFTINT_MPSAFE,
 	(void (*)(void *))ip6hand, NULL);
+	netisrs[NETISR_MPLS] = softint_establish(SOFTINT_NET | SOFTINT_MPSAFE,
+	(void (*)(void *))mplshand, NULL);
 }

Index: src/sys/rump/net/Makefile.rumpnetcomp
diff -u src/sys/rump/net/Makefile.rumpnetcomp:1.5 src/sys/rump/net/Makefile.rumpnetcomp:1.6
--- src/sys/rump/net/Makefile.rumpnetcomp:1.5	Wed Aug 15 17:56:58 2012
+++ src/sys/rump/net/Makefile.rumpnetcomp	Thu Jul 18 15:59:27 2013
@@ -1,7 +1,8 @@
-#	$NetBSD: Makefile.rumpnetcomp,v 1.5 2012/08/15 17:56:58 rmind Exp $
+#	$NetBSD: Makefile.rumpnetcomp,v 1.6 2013/07/18 15:59:27 kefren Exp $
 #
 
-RUMPNETCOMP=	agr bridge net net80211 netbt netinet npf local shmif virtif
+RUMPNETCOMP=	agr bridge net net80211 netbt netinet netmpls npf
+RUMPNETCOMP+=	local shmif virtif
 
 RUMPNETSOCKIN=	sockin
 

Index: src/sys/rump/net/lib/libnet/Makefile
diff -u src/sys/rump/net/lib/libnet/Makefile:1.17 src/sys/rump/net/lib/libnet/Makefile:1.18
--- src/sys/rump/net/lib/libnet/Makefile:1.17	Sat Jun  1 10:54:24 2013
+++ src/sys/rump/net/lib/libnet/Makefile	Thu Jul 18 15:59:28 2013
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.17 2013/06/01 10:54:24 pooka Exp $
+#	$NetBSD: Makefile,v 1.18 2013/07/18 15:59:28 kefren Exp $
 #
 
 .PATH:	${.CURDIR}/../../../../net ${.CURDIR}/../../../../compat/common
@@ -15,6 +15,7 @@ CPPFLAGS+=	-I${.CURDIR}/opt -I${.CURDIR}
 CPPFLAGS+=	-DCOMPAT_OIFREQ -DCOMPAT_OIFDATA
 
 .include "${.CURDIR}/../libnetinet/Makefile.inc"
+.include "${.CURDIR}/../libnetmpls/Makefile.inc"
 
 .include 
 .include 

Index: src/sys/rump/net/lib/libnet/opt/opt_mpls.h
diff -u src/sys/rump/net/lib/libnet/opt/opt_mpls.h:1.1 src/sys/rump/net/lib/libnet/opt/opt_mpls.h:1.2
--- src/sys/rump/net/lib/libnet/opt/opt_mpls.h:1.1	Sat Jun 26 14:24:28 2010
+++ src/sys/rump/net/lib/libnet/opt/opt_mpls.h	Thu Jul 18 15:59:28 2013
@@ -1,3 +1,3 @@
-/* $NetBSD: opt_mpls.h,v 1.1 2010/06/26 14:24:28 kefren Exp $ */
+/* $NetBSD: opt_mpls.h,v 1.2 2013/07/18 15:59:28 kefren Exp $ */
 
-/* XXX: dummy */
+#define	MPLS 1

Added files:

Index: src/sys/rump/net/lib/libnetmpls/Makefile
diff -u /dev/null src/sys/rump/ne

CVS commit: src/usr.sbin/ldpd

2013-07-18 Thread Mihai Chelaru
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

CVS commit: src/sys/netmpls

2013-07-17 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Thu Jul 18 06:23:07 UTC 2013

Modified Files:
src/sys/netmpls: mpls_proto.c

Log Message:
explicitly call sysctl setup in init. Needed for future dynamic loading


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/netmpls/mpls_proto.c

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

Modified files:

Index: src/sys/netmpls/mpls_proto.c
diff -u src/sys/netmpls/mpls_proto.c:1.3 src/sys/netmpls/mpls_proto.c:1.4
--- src/sys/netmpls/mpls_proto.c:1.3	Wed Feb  1 16:49:36 2012
+++ src/sys/netmpls/mpls_proto.c	Thu Jul 18 06:23:07 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: mpls_proto.c,v 1.3 2012/02/01 16:49:36 christos Exp $ */
+/*	$NetBSD: mpls_proto.c,v 1.4 2013/07/18 06:23:07 kefren Exp $ */
 
 /*
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mpls_proto.c,v 1.3 2012/02/01 16:49:36 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mpls_proto.c,v 1.4 2013/07/18 06:23:07 kefren Exp $");
 
 #include "opt_inet.h"
 #include "opt_mbuftrace.h"
@@ -51,6 +51,7 @@ struct ifqueue mplsintrq;
 
 static int mpls_usrreq(struct socket *, int, struct mbuf *, struct mbuf *,
 	struct mbuf *, struct lwp *);
+static void sysctl_net_mpls_setup(struct sysctllog **);
 
 #ifdef MBUFTRACE
 struct mowner mpls_owner = MOWNER_INIT("MPLS", "");
@@ -72,6 +73,8 @@ void mpls_init(void)
 #endif
 	memset(&mplsintrq, 0, sizeof(mplsintrq));
 	mplsintrq.ifq_maxlen = 256;
+
+	sysctl_net_mpls_setup(NULL);
 }
 
 DOMAIN_DEFINE(mplsdomain);
@@ -134,7 +137,8 @@ mpls_usrreq(struct socket *so, int req, 
 /*
  * Sysctl for MPLS variables.
  */
-SYSCTL_SETUP(sysctl_net_mpls_setup, "sysctl net.mpls subtree setup")
+static void
+sysctl_net_mpls_setup(struct sysctllog **clog)
 {
 
 sysctl_createv(clog, 0, NULL, NULL,



CVS commit: src/usr.sbin/ldpd

2013-07-17 Thread Mihai Chelaru
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

CVS commit: src/usr.sbin/ldpd

2013-07-16 Thread Mihai Chelaru
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

2013-07-16 Thread Mihai Chelaru
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

2013-07-15 Thread Mihai Chelaru
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 
+#include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -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 *, int);
 void	mask_addr(union sock

CVS commit: src/sys/net

2013-07-15 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Mon Jul 15 12:10:34 UTC 2013

Modified Files:
src/sys/net: if_mpls.c

Log Message:
stop abusing kmem during softint context


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/net/if_mpls.c

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

Modified files:

Index: src/sys/net/if_mpls.c
diff -u src/sys/net/if_mpls.c:1.8 src/sys/net/if_mpls.c:1.9
--- src/sys/net/if_mpls.c:1.8	Sun Jul  3 18:46:12 2011
+++ src/sys/net/if_mpls.c	Mon Jul 15 12:10:34 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_mpls.c,v 1.8 2011/07/03 18:46:12 kefren Exp $ */
+/*	$NetBSD: if_mpls.c,v 1.9 2013/07/15 12:10:34 kefren Exp $ */
 
 /*
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_mpls.c,v 1.8 2011/07/03 18:46:12 kefren Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_mpls.c,v 1.9 2013/07/15 12:10:34 kefren Exp $");
 
 #include "opt_inet.h"
 #include "opt_mpls.h"
@@ -38,7 +38,6 @@ __KERNEL_RCSID(0, "$NetBSD: if_mpls.c,v 
 #include 
 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -518,25 +517,21 @@ mpls_unlabel_inet(struct mbuf *m)
 static struct mbuf *
 mpls_label_inet(struct mbuf *m, union mpls_shim *ms, uint offset)
 {
-	struct ip *iphdr;
+	struct ip iphdr;
 
 	if (mpls_mapttl_inet || mpls_mapprec_inet) {
 		if ((m->m_len < sizeof(struct ip)) &&
 		(m = m_pullup(m, offset + sizeof(struct ip))) == 0)
 			return NULL; /* XXX */
-		iphdr = kmem_alloc(sizeof(struct ip), KM_NOSLEEP);
-		if (iphdr == NULL)
-			return NULL;
-		m_copydata(m, offset, sizeof(struct ip), iphdr);
+		m_copydata(m, offset, sizeof(struct ip), &iphdr);
 
 		/* Map TTL */
 		if (mpls_mapttl_inet)
-			ms->shim.ttl = iphdr->ip_ttl;
+			ms->shim.ttl = iphdr.ip_ttl;
 
 		/* Copy IP precedence to EXP */
 		if (mpls_mapprec_inet)
-			ms->shim.exp = ((u_int8_t)iphdr->ip_tos) >> 5;
-		kmem_free (iphdr, sizeof(struct ip));
+			ms->shim.exp = ((u_int8_t)iphdr.ip_tos) >> 5;
 	}
 
 	if ((m = mpls_prepend_shim(m, ms)) == NULL)
@@ -592,23 +587,19 @@ mpls_unlabel_inet6(struct mbuf *m)
 static struct mbuf *
 mpls_label_inet6(struct mbuf *m, union mpls_shim *ms, uint offset)
 {
-	struct ip6_hdr *ip6h;
+	struct ip6_hdr ip6h;
 
 	if (mpls_mapttl_inet6 || mpls_mapclass_inet6) {
 		if (m->m_len < sizeof(struct ip6_hdr) &&
 		(m = m_pullup(m, offset + sizeof(struct ip6_hdr))) == 0)
 			return NULL;
-		ip6h = kmem_alloc(sizeof(struct ip6_hdr), KM_NOSLEEP);
-		if (ip6h == NULL)
-			return NULL;
-		m_copydata(m, offset, sizeof(struct ip6_hdr), ip6h);
+		m_copydata(m, offset, sizeof(struct ip6_hdr), &ip6h);
 
 		if (mpls_mapttl_inet6)
-			ms->shim.ttl = ip6h->ip6_hlim;
+			ms->shim.ttl = ip6h.ip6_hlim;
 
 		if (mpls_mapclass_inet6)
-			ms->shim.exp = ip6h->ip6_vfc << 1 >> 5;
-		kmem_free(ip6h, sizeof(struct ip6_hdr));
+			ms->shim.exp = ip6h.ip6_vfc << 1 >> 5;
 	}
 
 	if ((m = mpls_prepend_shim(m, ms)) == NULL)



CVS commit: src/usr.sbin/ldpd

2013-07-12 Thread Mihai Chelaru
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 

CVS commit: src/usr.sbin/ldpd

2013-07-11 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Thu Jul 11 18:02:03 UTC 2013

Modified Files:
src/usr.sbin/ldpd: mpls_routes.c tlv.h

Log Message:
add code for address and address withdraw messages
get rid of unused fields in tlv struct


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/usr.sbin/ldpd/mpls_routes.c
cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/ldpd/tlv.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.c
diff -u src/usr.sbin/ldpd/mpls_routes.c:1.12 src/usr.sbin/ldpd/mpls_routes.c:1.13
--- src/usr.sbin/ldpd/mpls_routes.c:1.12	Thu Jul 11 10:46:19 2013
+++ src/usr.sbin/ldpd/mpls_routes.c	Thu Jul 11 18:02:03 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: mpls_routes.c,v 1.12 2013/07/11 10:46:19 kefren Exp $ */
+/* $NetBSD: mpls_routes.c,v 1.13 2013/07/11 18:02:03 kefren Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -54,6 +54,7 @@
 #include "tlv_stack.h"
 #include "label.h"
 #include "mpls_routes.h"
+#include "socketops.h"
 
 extern int  route_socket;
 int rt_seq = 0;
@@ -68,6 +69,7 @@ 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);
 
 extern struct sockaddr mplssockaddr;
 
@@ -565,7 +567,6 @@ get_route(struct rt_msg * rg, const unio
 	return LDP_E_OK;
 }
 
-
 /* triggered when a route event occurs */
 int 
 check_route(struct rt_msg * rg, uint rlen)
@@ -580,19 +581,18 @@ check_route(struct rt_msg * rg, uint rle
 	gate[0] = 0;
 	pref[0] = 0;
 
-	if (rlen <= sizeof(struct rt_msghdr))
-		return LDP_E_ROUTE_ERROR;
-
-	if (rg->m_rtm.rtm_version != RTM_VERSION)
+	if (rlen <= sizeof(struct rt_msghdr) ||
+	rg->m_rtm.rtm_version != RTM_VERSION)
 		return LDP_E_ROUTE_ERROR;
 
-	if ((rg->m_rtm.rtm_flags & RTF_DONE) == 0)
+	if (rg->m_rtm.rtm_type == RTM_NEWADDR ||
+	rg->m_rtm.rtm_type == RTM_DELADDR)
+		return check_if_addr_updown(rg);
+	if (rg->m_rtm.rtm_pid == getpid() ||
+	((rg->m_rtm.rtm_flags & RTF_DONE) == 0))
 		return LDP_E_OK;
 
-	if (rg->m_rtm.rtm_pid == getpid())	/* We did it.. */
-		return LDP_E_OK;
-	else
-		debugp("Check route triggered by PID: %d\n", rg->m_rtm.rtm_pid);
+	debugp("Check route triggered by PID: %d\n", rg->m_rtm.rtm_pid);
 
 	so_dest = (union sockunion *) rg->m_space;
 
@@ -738,6 +738,48 @@ check_route(struct rt_msg * rg, uint rle
 	return LDP_E_OK;
 }
 
+/*
+ * Checks NEWADDR and DELADDR messages and sends announcements accordingly
+ */
+static int
+check_if_addr_updown(struct rt_msg * rg)
+{
+	union sockunion *ifa, *netmask;
+	struct ldp_peer *p;
+	struct address_list_tlv al_tlv;
+
+	if ((rg->m_rtm.rtm_addrs & RTA_NETMASK) == 0 ||
+	(rg->m_rtm.rtm_addrs & RTA_IFA) == 0)
+		return LDP_E_ROUTE_ERROR;
+
+	ifa = netmask = (union sockunion *) rg->m_space;
+	if (netmask->sa.sa_family != AF_INET)
+		return LDP_E_OK;
+
+	if (rg->m_rtm.rtm_addrs & RTA_IFP)
+		ifa = GETNEXT(netmask);
+	ifa = GETNEXT(ifa);
+
+	if (ifa->sa.sa_family != AF_INET)
+		return LDP_E_OK;
+
+	memset(&al_tlv, 0, sizeof(al_tlv));
+	al_tlv.type = rg->m_rtm.rtm_type == RTM_NEWADDR ? htons(LDP_ADDRESS) :
+	htons(LDP_ADDRESS_WITHDRAW);
+	al_tlv.length = htons(sizeof(al_tlv) - TLV_TYPE_LENGTH);
+	al_tlv.messageid = htonl(get_message_id());
+	al_tlv.a_type = htons(TLV_ADDRESS_LIST);
+	al_tlv.a_length = htons(sizeof(al_tlv.a_af) + sizeof(al_tlv.a_address));
+	al_tlv.a_af = htons(LDP_AF_INET);
+	memcpy(&al_tlv.a_address, &ifa->sin.sin_addr, sizeof(al_tlv.a_address));
+
+	SLIST_FOREACH(p, &ldp_peer_head, peers)
+		if (p->state == LDP_PEER_ESTABLISHED)
+			send_tlv(p, (struct tlv *)&al_tlv);
+
+	return LDP_E_OK;
+}
+
 int 
 bind_current_routes()
 {

Index: src/usr.sbin/ldpd/tlv.h
diff -u src/usr.sbin/ldpd/tlv.h:1.3 src/usr.sbin/ldpd/tlv.h:1.4
--- src/usr.sbin/ldpd/tlv.h:1.3	Sat Jan 26 17:29:55 2013
+++ src/usr.sbin/ldpd/tlv.h	Thu Jul 11 18:02:03 2013
@@ -1,4 +1,4 @@
-/* $NetBSD: tlv.h,v 1.3 2013/01/26 17:29:55 kefren Exp $ */
+/* $NetBSD: tlv.h,v 1.4 2013/07/11 18:02:03 kefren Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -62,8 +62,6 @@ struct tlv {
 	uint16_t   type;
 	uint16_t   length;
 	uint32_t   messageid;
-	void   *value;
-	struct ldp_pdu *pdu;
 }   __packed;
 
 /* Common Hello TLV structure */



CVS commit: src/usr.sbin/ldpd

2013-07-11 Thread Mihai Chelaru
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
--- src/us

CVS commit: src/usr.sbin/ldpd

2013-07-11 Thread Mihai Chelaru
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

2013-07-10 Thread Mihai Chelaru
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

2013-07-10 Thread Mihai Chelaru
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 2

CVS commit: src/usr.sbin/ldpd

2013-06-23 Thread Mihai Chelaru
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

2013-05-08 Thread Mihai Chelaru
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

2013-02-05 Thread Mihai Chelaru
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

CVS commit: src/usr.sbin/ldpd

2013-02-04 Thread Mihai Chelaru
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

2013-02-04 Thread Mihai Chelaru
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 

CVS commit: src/usr.sbin/ldpd

2013-02-04 Thread Mihai Chelaru
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

2013-02-04 Thread Mihai Chelaru
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

2013-02-03 Thread Mihai Chelaru
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/sys/netinet

2013-02-01 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Sat Feb  2 07:00:42 UTC 2013

Modified Files:
src/sys/netinet: ip_output.c

Log Message:
get rid of ip_len local variable. Use ntohs(ip->ip_len) like the rest
of the code in the two places this variable was used


To generate a diff of this commit:
cvs rdiff -u -r1.217 -r1.218 src/sys/netinet/ip_output.c

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

Modified files:

Index: src/sys/netinet/ip_output.c
diff -u src/sys/netinet/ip_output.c:1.217 src/sys/netinet/ip_output.c:1.218
--- src/sys/netinet/ip_output.c:1.217	Mon Jun 25 15:28:39 2012
+++ src/sys/netinet/ip_output.c	Sat Feb  2 07:00:40 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip_output.c,v 1.217 2012/06/25 15:28:39 christos Exp $	*/
+/*	$NetBSD: ip_output.c,v 1.218 2013/02/02 07:00:40 kefren Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.217 2012/06/25 15:28:39 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_output.c,v 1.218 2013/02/02 07:00:40 kefren Exp $");
 
 #include "opt_pfil_hooks.h"
 #include "opt_inet.h"
@@ -187,7 +187,6 @@ ip_output(struct mbuf *m0, ...)
 	struct secpolicy *sp = NULL;
 	int s;
 #endif
-	u_int16_t ip_len;
 	union {
 		struct sockaddr		dst;
 		struct sockaddr_in	dst4;
@@ -492,9 +491,6 @@ sendit:
 	(rt->rt_rmx.rmx_locks & RTV_MTU) == 0)
 		ip->ip_off |= htons(IP_DF);
 
-	/* Remember the current ip_len */
-	ip_len = ntohs(ip->ip_len);
-
 #ifdef FAST_IPSEC
 	/*
 	 * Check the security policy (SP) for the packet and, if
@@ -598,7 +594,6 @@ spd_done:
 
 	ip = mtod(m, struct ip *);
 	hlen = ip->ip_hl << 2;
-	ip_len = ntohs(ip->ip_len);
 #endif /* PFIL_HOOKS */
 
 	m->m_pkthdr.csum_data |= hlen << 16;
@@ -620,11 +615,11 @@ spd_done:
 	 * If small enough for mtu of path, or if using TCP segmentation
 	 * offload, can just send directly.
 	 */
-	if (ip_len <= mtu ||
+	if (ntohs(ip->ip_len) <= mtu ||
 	(m->m_pkthdr.csum_flags & M_CSUM_TSOv4) != 0) {
 #if IFA_STATS
 		if (ia)
-			ia->ia_ifa.ifa_data.ifad_outbytes += ip_len;
+			ia->ia_ifa.ifa_data.ifad_outbytes += ntohs(ip->ip_len);
 #endif
 		/*
 		 * Always initialize the sum to 0!  Some HW assisted



CVS commit: src/usr.sbin/ldpd

2013-01-28 Thread Mihai Chelaru
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

2013-01-28 Thread Mihai Chelaru
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

2013-01-28 Thread Mihai Chelaru
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

2013-01-28 Thread Mihai Chelaru
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,
+		 

CVS commit: src/usr.sbin/ldpd

2013-01-26 Thread Mihai Chelaru
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

2013-01-26 Thread Mihai Chelaru
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 
 #include 
 #include 
 
@@ -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 
 #include 
 
+#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 outsid

CVS commit: src/usr.sbin/ldpd

2013-01-26 Thread Mihai Chelaru
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 
 
 /* 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

2013-01-26 Thread Mihai Chelaru
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/sys/netinet6

2013-01-25 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Fri Jan 25 10:33:53 UTC 2013

Modified Files:
src/sys/netinet6: ip6_output.c

Log Message:
don't return hlim when asked for multicast loop flag


To generate a diff of this commit:
cvs rdiff -u -r1.150 -r1.151 src/sys/netinet6/ip6_output.c

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

Modified files:

Index: src/sys/netinet6/ip6_output.c
diff -u src/sys/netinet6/ip6_output.c:1.150 src/sys/netinet6/ip6_output.c:1.151
--- src/sys/netinet6/ip6_output.c:1.150	Sat Jul 21 14:52:40 2012
+++ src/sys/netinet6/ip6_output.c	Fri Jan 25 10:33:53 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_output.c,v 1.150 2012/07/21 14:52:40 gdt Exp $	*/
+/*	$NetBSD: ip6_output.c,v 1.151 2013/01/25 10:33:53 kefren Exp $	*/
 /*	$KAME: ip6_output.c,v 1.172 2001/03/25 09:55:56 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.150 2012/07/21 14:52:40 gdt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.151 2013/01/25 10:33:53 kefren Exp $");
 
 #include "opt_inet.h"
 #include "opt_inet6.h"
@@ -2554,7 +2554,7 @@ ip6_getmoptions(struct sockopt *sopt, st
 
 	case IPV6_MULTICAST_LOOP:
 		if (im6o == NULL)
-			optval = ip6_defmcasthlim;
+			optval = IPV6_DEFAULT_MULTICAST_LOOP;
 		else
 			optval = im6o->im6o_multicast_loop;
 



CVS commit: src/usr.sbin/ldpd

2013-01-16 Thread Mihai Chelaru
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

2012-11-12 Thread Mihai Chelaru
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

2012-11-12 Thread Mihai Chelaru
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 
 
@@ -22,4 +22,8 @@ SRCS=   conffile.c \
 
 LDADD+=	-lcrypt
 
+.if (${USE_INET6} != "no")
+CPPFLAGS+=-DINET6
+.endif
+
 .include 
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 
 
 #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  peer_addr;
+	struct 

CVS commit: src

2012-06-28 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Thu Jun 28 16:34:07 UTC 2012

Modified Files:
src/etc/mtree: special
src/usr.sbin/postinstall: postinstall

Log Message:
add ldpd rc.d script here too


To generate a diff of this commit:
cvs rdiff -u -r1.141 -r1.142 src/etc/mtree/special
cvs rdiff -u -r1.137 -r1.138 src/usr.sbin/postinstall/postinstall

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

Modified files:

Index: src/etc/mtree/special
diff -u src/etc/mtree/special:1.141 src/etc/mtree/special:1.142
--- src/etc/mtree/special:1.141	Sat Dec 17 13:37:49 2011
+++ src/etc/mtree/special	Thu Jun 28 16:34:07 2012
@@ -1,4 +1,4 @@
-#	$NetBSD: special,v 1.141 2011/12/17 13:37:49 tsutsui Exp $
+#	$NetBSD: special,v 1.142 2012/06/28 16:34:07 kefren Exp $
 #	@(#)special	8.2 (Berkeley) 1/23/94
 #
 # This file may be overwritten on upgrades.
@@ -220,6 +220,7 @@
 ./etc/rc.d/isibootd		type=file mode=0555
 ./etc/rc.d/kdc			type=file mode=0555
 ./etc/rc.d/ldconfig		type=file mode=0555
+./etc/rc.d/ldpd			type=file mode=0555
 ./etc/rc.d/local		type=file mode=0555
 ./etc/rc.d/lpd			type=file mode=0555
 ./etc/rc.d/lvm			type=file mode=0555

Index: src/usr.sbin/postinstall/postinstall
diff -u src/usr.sbin/postinstall/postinstall:1.137 src/usr.sbin/postinstall/postinstall:1.138
--- src/usr.sbin/postinstall/postinstall:1.137	Fri Jun  1 21:59:06 2012
+++ src/usr.sbin/postinstall/postinstall	Thu Jun 28 16:34:06 2012
@@ -1,6 +1,6 @@
 #!/bin/sh
 #
-# $NetBSD: postinstall,v 1.137 2012/06/01 21:59:06 jnemeth Exp $
+# $NetBSD: postinstall,v 1.138 2012/06/28 16:34:06 kefren Exp $
 #
 # Copyright (c) 2002-2008 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -1183,7 +1183,7 @@ do_rc()
 		identd ifwatchd inetd ipfilter ipfs ipmon ipnat ipsec \
 		irdaattach iscsi_target isdnd isibootd \
 		kdc \
-		ldconfig local lpd lvm\
+		ldconfig ldpd local lpd lvm\
 		makemandb mdnsd mixerctl mopd motd mountall mountcritlocal \
 		mountcritremote mountd moused mrouted \
 		named ndbootd network newsyslog nfsd nfslocking npf \



CVS commit: src/usr.sbin/ldpd

2011-07-06 Thread Mihai Chelaru
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/sys/net

2011-07-03 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Sun Jul  3 18:46:12 UTC 2011

Modified Files:
src/sys/net: if_mpls.c

Log Message:
Avoid putting implicit null labels on the wire


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/net/if_mpls.c

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

Modified files:

Index: src/sys/net/if_mpls.c
diff -u src/sys/net/if_mpls.c:1.7 src/sys/net/if_mpls.c:1.8
--- src/sys/net/if_mpls.c:1.7	Wed Jun 22 19:08:29 2011
+++ src/sys/net/if_mpls.c	Sun Jul  3 18:46:12 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_mpls.c,v 1.7 2011/06/22 19:08:29 kefren Exp $ */
+/*	$NetBSD: if_mpls.c,v 1.8 2011/07/03 18:46:12 kefren Exp $ */
 
 /*
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_mpls.c,v 1.7 2011/06/22 19:08:29 kefren Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_mpls.c,v 1.8 2011/07/03 18:46:12 kefren Exp $");
 
 #include "opt_inet.h"
 #include "opt_mpls.h"
@@ -218,7 +218,8 @@
 
 	while (psize <= rt_gettag(rt)->sa_len - sizeof(mh)) {
 		pms++;
-		if ((m = mpls_prepend_shim(m, &mh)) == NULL)
+		if (mh.shim.label != MPLS_LABEL_IMPLNULL &&
+		((m = mpls_prepend_shim(m, &mh)) == NULL))
 			return ENOBUFS;
 		memset(&mh, 0, sizeof(mh));
 		mh.s_addr = ntohl(pms->s_addr);
@@ -392,7 +393,8 @@
 		tshim.s_addr = ntohl(htag->s_addr);
 		tshim.shim.bos = tshim.shim.exp = 0;
 		tshim.shim.ttl = mpls_defttl;
-		if ((m = mpls_prepend_shim(m, &tshim)) == NULL)
+		if (tshim.shim.label != MPLS_LABEL_IMPLNULL &&
+		((m = mpls_prepend_shim(m, &tshim)) == NULL))
 			return ENOBUFS;
 		psize += sizeof(tshim);
 	}



CVS commit: src/share/man/man4

2011-07-03 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Sun Jul  3 07:25:52 UTC 2011

Modified Files:
src/share/man/man4: route.4

Log Message:
add RTA_TAG as defined in 


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/share/man/man4/route.4

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

Modified files:

Index: src/share/man/man4/route.4
diff -u src/share/man/man4/route.4:1.17 src/share/man/man4/route.4:1.18
--- src/share/man/man4/route.4:1.17	Mon Nov 15 21:19:59 2010
+++ src/share/man/man4/route.4	Sun Jul  3 07:25:52 2011
@@ -1,4 +1,4 @@
-.\"	$NetBSD: route.4,v 1.17 2010/11/15 21:19:59 wiz Exp $
+.\"	$NetBSD: route.4,v 1.18 2011/07/03 07:25:52 kefren Exp $
 .\"
 .\" Copyright (c) 1990, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -327,6 +327,7 @@
 #define RTA_IFA   0x20   /* interface addr sockaddr present */
 #define RTA_AUTHOR0x40   /* sockaddr for author of redirect */
 #define RTA_BRD   0x80   /* for NEWADDR, broadcast or p-p dest addr */
+#define RTA_TAG   0x100  /* route tag */
 .Ed
 .Sh SEE ALSO
 .Xr socket 2 ,



CVS commit: src/sbin/route

2011-07-03 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Sun Jul  3 07:20:37 UTC 2011

Modified Files:
src/sbin/route: route.8

Log Message:
Mention -mpls and -tag and xref mpls(4)
bin/45071


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/sbin/route/route.8

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

Modified files:

Index: src/sbin/route/route.8
diff -u src/sbin/route/route.8:1.42 src/sbin/route/route.8:1.43
--- src/sbin/route/route.8:1.42	Thu Jun 16 23:35:35 2011
+++ src/sbin/route/route.8	Sun Jul  3 07:20:37 2011
@@ -1,4 +1,4 @@
-.\"	$NetBSD: route.8,v 1.42 2011/06/16 23:35:35 yamt Exp $
+.\"	$NetBSD: route.8,v 1.43 2011/07/03 07:20:37 kefren Exp $
 .\"
 .\" Copyright (c) 1983, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -152,8 +152,9 @@
 .Fl xns ,
 .Fl atalk ,
 .Fl inet ,
+.Fl inet6,
 or
-.Fl inet6
+.Fl mpls
 modifiers, only routes having destinations with addresses in the
 delineated family will be manipulated.
 .Pp
@@ -244,6 +245,17 @@
 and the names must be numeric specifications rather than
 symbolic names.
 .Pp
+The optional modifiers
+.Fl mpls ,
+and
+.Fl tag
+specify that all subsequent addresses are in the
+.Tn MPLS
+address family.
+See
+.Xr mpls 4 ,
+for examples about setting routes involving MPLS.
+.Pp
 The optional
 .Fl netmask
 qualifier is intended
@@ -391,6 +403,7 @@
 .El
 .Sh SEE ALSO
 .Xr esis 4 ,
+.Xr mpls 4 ,
 .Xr netintro 4 ,
 .Xr route 4 ,
 .Xr routed 8 ,



CVS commit: src/share/man/man4

2011-07-03 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Sun Jul  3 07:00:48 UTC 2011

Modified Files:
src/share/man/man4: mpls.4

Log Message:
correct two examples and add a couple more for multiple tags


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/share/man/man4/mpls.4

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

Modified files:

Index: src/share/man/man4/mpls.4
diff -u src/share/man/man4/mpls.4:1.4 src/share/man/man4/mpls.4:1.5
--- src/share/man/man4/mpls.4:1.4	Thu Jun 16 03:23:08 2011
+++ src/share/man/man4/mpls.4	Sun Jul  3 07:00:47 2011
@@ -1,4 +1,4 @@
-.\" $NetBSD: mpls.4,v 1.4 2011/06/16 03:23:08 yamt Exp $
+.\" $NetBSD: mpls.4,v 1.5 2011/07/03 07:00:47 kefren Exp $
 .\"
 .\" Copyright (c) 2010 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -183,7 +183,7 @@
 .It
 Route IP packets into MPLS domain with a specific tag
 .Bd -literal
-# route add 10.0.0.0/8 -ifp mpls0 -tag 25 192.168.1.100
+# route add 10.0.0.0/8 -ifp mpls0 -tag 25 -inet 192.168.1.100
 .Ed
 .It
 Create a static MPLS forwarding rule - swap the incoming
@@ -208,7 +208,7 @@
 Route IP packets into MPLS domain but use a different source
 address for local generated packets.
 .Bd -literal
-# route add 10.0.0.0/8 -ifa 192.168.1.180 -ifp mpls0 -tag 25 192.168.1.100
+# route add 10.0.0.0/8 -ifa 192.168.1.180 -ifp mpls0 -tag 25 -inet 192.168.1.100
 .Ed
 For the latter example, setting an IP address for the mpls0 interface
 is not necessary.
@@ -217,6 +217,19 @@
 .Bd -literal
 # route add -mpls 60 -tag 3 -inet 192.168.1.100
 .Ed
+.It
+Route IP packets into MPLS domain and prepend more tags
+.Bd -literal
+# route add 10/8 -ifa 192.168.1.200 -ifp mpls0 -tag 20,30,40 -inet 192.168.1.100 
+.Ed
+For the above example, tag 20 will be inserted at Bottom of Stack, while tag 40
+will be set into the outermost shim.
+.It
+Replace label 60 with label 30, prepend two more labels: 40 and 41 (in this order)
+and forward the result to 192.168.1.100
+.Bd -literal
+# route add -mpls 60 -tag 30,40,41 -inet 192.168.1.100
+.Ed
 .El
 .Sh SEE ALSO
 .Xr netstat 1 ,



CVS commit: src/usr.sbin/ldpd

2011-07-02 Thread Mihai Chelaru
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/sys/net

2011-06-22 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Wed Jun 22 19:08:29 UTC 2011

Modified Files:
src/sys/net: if_mpls.c

Log Message:
make LSE prepend the rest of the shims in they exist


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/net/if_mpls.c

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

Modified files:

Index: src/sys/net/if_mpls.c
diff -u src/sys/net/if_mpls.c:1.6 src/sys/net/if_mpls.c:1.7
--- src/sys/net/if_mpls.c:1.6	Tue Jun 21 14:30:19 2011
+++ src/sys/net/if_mpls.c	Wed Jun 22 19:08:29 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_mpls.c,v 1.6 2011/06/21 14:30:19 kefren Exp $ */
+/*	$NetBSD: if_mpls.c,v 1.7 2011/06/22 19:08:29 kefren Exp $ */
 
 /*
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_mpls.c,v 1.6 2011/06/21 14:30:19 kefren Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_mpls.c,v 1.7 2011/06/22 19:08:29 kefren Exp $");
 
 #include "opt_inet.h"
 #include "opt_mpls.h"
@@ -218,7 +218,8 @@
 
 	while (psize <= rt_gettag(rt)->sa_len - sizeof(mh)) {
 		pms++;
-		m = mpls_prepend_shim(m, &mh);
+		if ((m = mpls_prepend_shim(m, &mh)) == NULL)
+			return ENOBUFS;
 		memset(&mh, 0, sizeof(mh));
 		mh.s_addr = ntohl(pms->s_addr);
 		mh.shim.bos = mh.shim.exp = 0;
@@ -305,6 +306,7 @@
 	union mpls_shim tshim, *htag;
 	struct rtentry *rt = NULL;
 	int error = ENOBUFS;
+	uint psize = sizeof(struct sockaddr_mpls);
 
 	if (m->m_len < sizeof(union mpls_shim) &&
 	(m = m_pullup(m, sizeof(union mpls_shim))) == NULL)
@@ -382,6 +384,19 @@
 	htag->shim.label = tshim.shim.label;
 	htag->s_addr = htonl(htag->s_addr);
 
+	/* check if there is anything more to prepend */
+	htag = &((struct sockaddr_mpls*)rt_gettag(rt))->smpls_addr;
+	while (psize <= rt_gettag(rt)->sa_len - sizeof(tshim)) {
+		htag++;
+		memset(&tshim, 0, sizeof(tshim));
+		tshim.s_addr = ntohl(htag->s_addr);
+		tshim.shim.bos = tshim.shim.exp = 0;
+		tshim.shim.ttl = mpls_defttl;
+		if ((m = mpls_prepend_shim(m, &tshim)) == NULL)
+			return ENOBUFS;
+		psize += sizeof(tshim);
+	}
+
 	error = mpls_send_frame(m, rt->rt_ifp, rt);
 
 done:



CVS commit: src/sbin/route

2011-06-21 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Wed Jun 22 04:57:28 UTC 2011

Modified Files:
src/sbin/route: route.c

Log Message:
don't compile tag functions if SMALL is defined. Should fix the build


To generate a diff of this commit:
cvs rdiff -u -r1.129 -r1.130 src/sbin/route/route.c

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

Modified files:

Index: src/sbin/route/route.c
diff -u src/sbin/route/route.c:1.129 src/sbin/route/route.c:1.130
--- src/sbin/route/route.c:1.129	Tue Jun 21 14:33:14 2011
+++ src/sbin/route/route.c	Wed Jun 22 04:57:28 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.129 2011/06/21 14:33:14 kefren Exp $	*/
+/*	$NetBSD: route.c,v 1.130 2011/06/22 04:57:28 kefren Exp $	*/
 
 /*
  * Copyright (c) 1983, 1989, 1991, 1993
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)route.c	8.6 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: route.c,v 1.129 2011/06/21 14:33:14 kefren Exp $");
+__RCSID("$NetBSD: route.c,v 1.130 2011/06/22 04:57:28 kefren Exp $");
 #endif
 #endif /* not lint */
 
@@ -1384,6 +1384,7 @@
 	/*NOTREACHED*/
 }
 
+#ifndef SMALL
 static sup
 readtag(sup su, const char *s)
 {
@@ -1433,6 +1434,7 @@
 	ms[where].shim.label = atoi(s);
 	ms[where].s_addr = htonl(ms[where].s_addr);
 }
+#endif	/* SMALL */
 
 int
 prefixlen(const char *s, struct sou *soup)



CVS commit: src/usr.bin/netstat

2011-06-21 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Tue Jun 21 19:46:36 UTC 2011

Modified Files:
src/usr.bin/netstat: netstat.1

Log Message:
add a sentence regarding multiple tags


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/usr.bin/netstat/netstat.1

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

Modified files:

Index: src/usr.bin/netstat/netstat.1
diff -u src/usr.bin/netstat/netstat.1:1.59 src/usr.bin/netstat/netstat.1:1.60
--- src/usr.bin/netstat/netstat.1:1.59	Mon Dec  6 09:28:38 2010
+++ src/usr.bin/netstat/netstat.1	Tue Jun 21 19:46:36 2011
@@ -1,4 +1,4 @@
-.\"	$NetBSD: netstat.1,v 1.59 2010/12/06 09:28:38 pooka Exp $
+.\"	$NetBSD: netstat.1,v 1.60 2011/06/21 19:46:36 kefren Exp $
 .\"
 .\" Copyright (c) 1983, 1990, 1992, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -268,7 +268,8 @@
 Show per-protocol statistics.
 If this option is repeated, counters with a value of zero are suppressed.
 .It Fl T
-Show MPLS Tags for the routing tables.
+Show MPLS Tags for the routing tables. If multiple tags exists, they will
+be comma separated, first tag being the BoS one.
 .It Fl v
 Show extra (verbose) detail for the routing tables
 .Pq Fl r ,



CVS commit: src/usr.bin/netstat

2011-06-21 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Tue Jun 21 19:42:46 UTC 2011

Modified Files:
src/usr.bin/netstat: netstat.h route.c show.c

Log Message:
print multiple tags if exists, comma separated


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/usr.bin/netstat/netstat.h
cvs rdiff -u -r1.77 -r1.78 src/usr.bin/netstat/route.c
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/netstat/show.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.bin/netstat/netstat.h
diff -u src/usr.bin/netstat/netstat.h:1.42 src/usr.bin/netstat/netstat.h:1.43
--- src/usr.bin/netstat/netstat.h:1.42	Tue May  3 18:28:46 2011
+++ src/usr.bin/netstat/netstat.h	Tue Jun 21 19:42:45 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: netstat.h,v 1.42 2011/05/03 18:28:46 dyoung Exp $	*/
+/*	$NetBSD: netstat.h,v 1.43 2011/06/21 19:42:45 kefren Exp $	*/
 
 /*
  * Copyright (c) 1992, 1993
@@ -175,4 +175,6 @@
 
 kvm_t *get_kvmd(void);
 
+char	*mpls_ntoa(const struct sockaddr *);
+
 #define PLEN(LONG_BIT / 4 + 2)

Index: src/usr.bin/netstat/route.c
diff -u src/usr.bin/netstat/route.c:1.77 src/usr.bin/netstat/route.c:1.78
--- src/usr.bin/netstat/route.c:1.77	Fri Feb  4 14:31:23 2011
+++ src/usr.bin/netstat/route.c	Tue Jun 21 19:42:45 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.77 2011/02/04 14:31:23 martin Exp $	*/
+/*	$NetBSD: route.c,v 1.78 2011/06/21 19:42:45 kefren Exp $	*/
 
 /*
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "from: @(#)route.c	8.3 (Berkeley) 3/9/94";
 #else
-__RCSID("$NetBSD: route.c,v 1.77 2011/02/04 14:31:23 martin Exp $");
+__RCSID("$NetBSD: route.c,v 1.78 2011/06/21 19:42:45 kefren Exp $");
 #endif
 #endif /* not lint */
 
@@ -270,13 +270,15 @@
 	putchar((rt->rt_rmx.rmx_locks & RTV_MTU) ? 'L' : ' ');
 	if (tagflag == 1) {
 		if (rt->rt_tag != NULL) {
-			const struct sockaddr_mpls *sampls = 
-			(const struct sockaddr_mpls*)kgetsa(rt->rt_tag);
-			union mpls_shim shim;
-
-			if (sampls->smpls_family == AF_MPLS) {
-shim.s_addr = ntohl(sampls->smpls_addr.s_addr);
-printf("%7d", shim.shim.label);
+			const struct sockaddr *tagsa = kgetsa(rt->rt_tag);
+			char *tagstr;
+
+			if (tagsa->sa_family == AF_MPLS) {
+tagstr = mpls_ntoa(tagsa);
+if (strlen(tagstr) < 7)
+	printf("%7s", tagstr);
+else
+	printf("%s", tagstr);
 			}
 			else
 printf("%7s", "-");

Index: src/usr.bin/netstat/show.c
diff -u src/usr.bin/netstat/show.c:1.13 src/usr.bin/netstat/show.c:1.14
--- src/usr.bin/netstat/show.c:1.13	Fri Feb  4 14:31:23 2011
+++ src/usr.bin/netstat/show.c	Tue Jun 21 19:42:45 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: show.c,v 1.13 2011/02/04 14:31:23 martin Exp $	*/
+/*	$NetBSD: show.c,v 1.14 2011/06/21 19:42:45 kefren Exp $	*/
 /*	$OpenBSD: show.c,v 1.1 2006/05/27 19:16:37 claudio Exp $	*/
 
 /*
@@ -61,7 +61,6 @@
 
 char	*any_ntoa(const struct sockaddr *);
 char	*link_print(struct sockaddr *);
-char	*mpls_ntoa(const struct sockaddr *); 
 
 #define PFKEYV2_CHUNK sizeof(u_int64_t)
 
@@ -382,17 +381,17 @@
 static void
 p_tag(const struct sockaddr *sa)
 {
-	const struct sockaddr_mpls *sampls =
-	(const struct sockaddr_mpls *)sa;
-	union mpls_shim mshim;
+	char *line;
 
 	if (sa == NULL || sa->sa_family != AF_MPLS) {
 		printf("%7s", "-");
 		return;
 	}
-
-	mshim.s_addr = ntohl(sampls->smpls_addr.s_addr);
-	printf("%7d", mshim.shim.label);
+	line = mpls_ntoa(sa);
+	if (strlen(line) < 7)
+		printf("%7s", line);
+	else
+		printf("%s", line);
 }
 
 static char line[MAXHOSTNAMELEN];
@@ -718,15 +717,22 @@
 char *
 mpls_ntoa(const struct sockaddr *sa)
 {
-	static char obuf[100];
-	const struct sockaddr_mpls *sm;
+	static char obuf[16];
+	const union mpls_shim *pms;
 	union mpls_shim ms;
+	int psize = sizeof(struct sockaddr_mpls);
 
-	sm = (const struct sockaddr_mpls*)sa;
-	ms.s_addr = ntohl(sm->smpls_addr.s_addr);
+	pms = &((const struct sockaddr_mpls*)sa)->smpls_addr;
+	ms.s_addr = ntohl(pms->s_addr);
 
-	snprintf(obuf, sizeof(obuf), "%u",
-	 ms.shim.label);
+	snprintf(obuf, sizeof(obuf), "%u", ms.shim.label);
 
+	while(psize < sa->sa_len) {
+		pms++;
+		ms.s_addr = ntohl(pms->s_addr);
+		snprintf(obuf, sizeof(obuf), "%s,%u", obuf,
+		ms.shim.label);
+		psize+=sizeof(ms);
+	}
 	return obuf;
 }



CVS commit: src/sbin/route

2011-06-21 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Tue Jun 21 14:33:14 UTC 2011

Modified Files:
src/sbin/route: route.c

Log Message:
Alloc dynamically sockunions in sou.
Teach route(8) about multiple tags. E.G.: -tag 100,20,33
XXX: needs documentation


To generate a diff of this commit:
cvs rdiff -u -r1.128 -r1.129 src/sbin/route/route.c

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

Modified files:

Index: src/sbin/route/route.c
diff -u src/sbin/route/route.c:1.128 src/sbin/route/route.c:1.129
--- src/sbin/route/route.c:1.128	Tue Feb  1 01:39:19 2011
+++ src/sbin/route/route.c	Tue Jun 21 14:33:14 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: route.c,v 1.128 2011/02/01 01:39:19 matt Exp $	*/
+/*	$NetBSD: route.c,v 1.129 2011/06/21 14:33:14 kefren Exp $	*/
 
 /*
  * Copyright (c) 1983, 1989, 1991, 1993
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)route.c	8.6 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: route.c,v 1.128 2011/02/01 01:39:19 matt Exp $");
+__RCSID("$NetBSD: route.c,v 1.129 2011/06/21 14:33:14 kefren Exp $");
 #endif
 #endif /* not lint */
 
@@ -97,7 +97,8 @@
 typedef union sockunion *sup;
 
 struct sou {
-	union sockunion so_dst, so_gate, so_mask, so_genmask, so_ifa, so_ifp, so_mpls;
+	union sockunion *so_dst, *so_gate, *so_mask, *so_genmask, *so_ifa,
+		*so_ifp, *so_mpls;
 };
 
 static char *any_ntoa(const struct sockaddr *);
@@ -116,6 +117,8 @@
 static void monitor(void);
 static int print_getmsg(struct rt_msghdr *, int, struct sou *);
 static const char *linkstate(struct if_msghdr *);
+static sup readtag(sup, const char *);
+static void addtag(sup, const char *, int);
 #endif /* SMALL */
 static int rtmsg(int, int, struct sou *);
 static void mask_addr(struct sou *);
@@ -588,11 +591,21 @@
 	case AF_MPLS:
 		{
 		union mpls_shim ms;
+		const union mpls_shim *pms;
+		int psize = sizeof(struct sockaddr_mpls);
 
 		ms.s_addr =((const struct sockaddr_mpls*)sa)->smpls_addr.s_addr;
 		ms.s_addr = ntohl(ms.s_addr);
 
 		snprintf(line, sizeof(line), "%u", ms.shim.label);
+		pms = &((const struct sockaddr_mpls*)sa)->smpls_addr;
+		while(psize < sa->sa_len) {
+			pms++;
+			ms.s_addr = ntohl(pms->s_addr);
+			snprintf(line, sizeof(line), "%s %u", line,
+			ms.shim.label);
+			psize += sizeof(ms);
+		}
 		break;
 		}
 #endif /* SMALL */
@@ -795,7 +808,18 @@
 	struct hostent *hp = 0;
 	struct sou sou, *soup = &sou;
 
-	memset(&sou, 0, sizeof(sou));
+	sou.so_dst = calloc(1, sizeof(union sockunion));
+	sou.so_gate = calloc(1, sizeof(union sockunion));
+	sou.so_mask = calloc(1, sizeof(union sockunion));
+	sou.so_genmask = calloc(1, sizeof(union sockunion));
+	sou.so_ifa = calloc(1, sizeof(union sockunion));
+	sou.so_ifp = calloc(1, sizeof(union sockunion));
+	sou.so_mpls = calloc(1, sizeof(union sockunion));
+
+	if (sou.so_dst == NULL || sou.so_gate == NULL || sou.so_mask == NULL ||
+	sou.so_genmask == NULL || sou.so_ifa == NULL || sou.so_ifp == NULL ||
+	sou.so_mpls == NULL)
+		errx(EXIT_FAILURE, "Cannot allocate memory");
 
 	cmd = argv[0];
 	af = AF_UNSPEC;
@@ -849,6 +873,7 @@
 			case K_TAG:
 if (!--argc)
 	usage(1+*argv);
+af = AF_MPLS;
 aflen = sizeof(struct sockaddr_mpls);
 (void)getaddr(RTA_TAG, *++argv, 0, soup);
 break;
@@ -1016,7 +1041,7 @@
 			break;
 		if (af == AF_INET && *gateway && hp && hp->h_addr_list[1]) {
 			hp->h_addr_list++;
-			memmove(&soup->so_gate.sin.sin_addr, hp->h_addr_list[0],
+			memmove(&soup->so_gate->sin.sin_addr, hp->h_addr_list[0],
 			hp->h_length);
 		} else
 			break;
@@ -1030,13 +1055,21 @@
 			(void)printf(": gateway %s", gateway);
 			if (attempts > 1 && ret == 0 && af == AF_INET)
 			(void)printf(" (%s)",
-			inet_ntoa(soup->so_gate.sin.sin_addr));
+			inet_ntoa(soup->so_gate->sin.sin_addr));
 		}
 		if (ret == 0)
 			(void)printf("\n");
 		else
 			(void)printf(": %s\n", route_strerror(oerrno));
 	}
+	free(sou.so_dst);
+	free(sou.so_gate);
+	free(sou.so_mask);
+	free(sou.so_genmask);
+	free(sou.so_ifa);
+	free(sou.so_ifp);
+	free(sou.so_mpls);
+
 	return ret != 0;
 }
 
@@ -1090,7 +1123,7 @@
 			mask = -1;
 	}
 	isin->sin_addr.s_addr = htonl(addr);
-	sin = &soup->so_mask.sin;
+	sin = &soup->so_mask->sin;
 	sin->sin_addr.s_addr = htonl(mask);
 	sin->sin_len = 0;
 	sin->sin_family = 0;
@@ -1154,28 +1187,28 @@
 	rtm_addrs |= which;
 	switch (which) {
 	case RTA_DST:
-		su = &soup->so_dst;
+		su = soup->so_dst;
 		break;
 	case RTA_GATEWAY:
-		su = &soup->so_gate;
+		su = soup->so_gate;
 		break;
 	case RTA_NETMASK:
-		su = &soup->so_mask;
+		su = soup->so_mask;
 		break;
 	case RTA_GENMASK:
-		su = &soup->so_genmask;
+		su = soup->so_genmask;
 		break;
 	case RTA_IFP:
-		su = &soup->so_ifp;
+		su = soup->so_ifp;
 		afamily = AF_LINK;
 		break;
 	case RTA_IFA:
-		su = &soup->so_ifa;
+		su = soup->so_ifa;
 		su->sa.sa_family = af;
 		break;
 #ifndef SMALL
 	case RTA_TAG:
-		su = &soup->so_mpls;
+		su = soup->so_mpls;
 		afamily

CVS commit: src/sys/net

2011-06-21 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Tue Jun 21 14:30:20 UTC 2011

Modified Files:
src/sys/net: if_mpls.c

Log Message:
learn mpls interface how to prepend multiple shims by using a vector of
smpls_addrs in sockaddr_mpls. The number of smpls_addrs is found from
smpls_len. First label encountered is BoS.
XXX: need to do the same for LSE and this feature needs to be documented.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/net/if_mpls.c

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

Modified files:

Index: src/sys/net/if_mpls.c
diff -u src/sys/net/if_mpls.c:1.5 src/sys/net/if_mpls.c:1.6
--- src/sys/net/if_mpls.c:1.5	Fri Jun 17 09:15:24 2011
+++ src/sys/net/if_mpls.c	Tue Jun 21 14:30:19 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_mpls.c,v 1.5 2011/06/17 09:15:24 kefren Exp $ */
+/*	$NetBSD: if_mpls.c,v 1.6 2011/06/21 14:30:19 kefren Exp $ */
 
 /*
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_mpls.c,v 1.5 2011/06/17 09:15:24 kefren Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_mpls.c,v 1.6 2011/06/21 14:30:19 kefren Exp $");
 
 #include "opt_inet.h"
 #include "opt_mpls.h"
@@ -38,6 +38,7 @@
 #include 
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -84,12 +85,12 @@
 
 #ifdef INET
 static int mpls_unlabel_inet(struct mbuf *);
-static struct mbuf *mpls_label_inet(struct mbuf *, union mpls_shim *);
+static struct mbuf *mpls_label_inet(struct mbuf *, union mpls_shim *, uint);
 #endif
 
 #ifdef INET6
 static int mpls_unlabel_inet6(struct mbuf *);
-static struct mbuf *mpls_label_inet6(struct mbuf *, union mpls_shim *);
+static struct mbuf *mpls_label_inet6(struct mbuf *, union mpls_shim *, uint);
 #endif
 
 static struct mbuf *mpls_prepend_shim(struct mbuf *, union mpls_shim *);
@@ -190,9 +191,10 @@
 static int
 mpls_output(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *dst, struct rtentry *rt)
 {
-	union mpls_shim mh;
+	union mpls_shim mh, *pms;
 	struct rtentry *rt1;
 	int err;
+	uint psize = sizeof(struct sockaddr_mpls);
 
 	if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) {
 		m_freem(m);
@@ -206,20 +208,33 @@
 
 	bpf_mtap_af(ifp, dst->sa_family, m);
 
-	mh.s_addr=MPLS_GETSADDR(rt);
-	mh.shim.bos=1;
-	mh.shim.exp=0;
-	mh.shim.ttl=mpls_defttl;
+	memset(&mh, 0, sizeof(mh));
+	mh.s_addr = MPLS_GETSADDR(rt);
+	mh.shim.bos = 1;
+	mh.shim.exp = 0;
+	mh.shim.ttl = mpls_defttl;
+
+	pms = &((struct sockaddr_mpls*)rt_gettag(rt))->smpls_addr;
+
+	while (psize <= rt_gettag(rt)->sa_len - sizeof(mh)) {
+		pms++;
+		m = mpls_prepend_shim(m, &mh);
+		memset(&mh, 0, sizeof(mh));
+		mh.s_addr = ntohl(pms->s_addr);
+		mh.shim.bos = mh.shim.exp = 0;
+		mh.shim.ttl = mpls_defttl;
+		psize += sizeof(mh);
+	}
 
 	switch(dst->sa_family) {
 #ifdef INET
 	case AF_INET:
-		m = mpls_label_inet(m, &mh);
+		m = mpls_label_inet(m, &mh, psize - sizeof(struct sockaddr_mpls));
 		break;
 #endif
 #ifdef INET6
 	case AF_INET6:
-		m = mpls_label_inet6(m, &mh);
+		m = mpls_label_inet6(m, &mh, psize - sizeof(struct sockaddr_mpls));
 		break;
 #endif
 	default:
@@ -484,15 +499,18 @@
  * Prepend MPLS label
  */
 static struct mbuf *
-mpls_label_inet(struct mbuf *m, union mpls_shim *ms)
+mpls_label_inet(struct mbuf *m, union mpls_shim *ms, uint offset)
 {
 	struct ip *iphdr;
 
 	if (mpls_mapttl_inet || mpls_mapprec_inet) {
 		if ((m->m_len < sizeof(struct ip)) &&
-		(m = m_pullup(m, sizeof(struct ip))) == 0)
+		(m = m_pullup(m, offset + sizeof(struct ip))) == 0)
+			return NULL; /* XXX */
+		iphdr = kmem_alloc(sizeof(struct ip), KM_NOSLEEP);
+		if (iphdr == NULL)
 			return NULL;
-		iphdr = mtod(m, struct ip *);
+		m_copydata(m, offset, sizeof(struct ip), iphdr);
 
 		/* Map TTL */
 		if (mpls_mapttl_inet)
@@ -501,6 +519,7 @@
 		/* Copy IP precedence to EXP */
 		if (mpls_mapprec_inet)
 			ms->shim.exp = ((u_int8_t)iphdr->ip_tos) >> 5;
+		kmem_free (iphdr, sizeof(struct ip));
 	}
 
 	if ((m = mpls_prepend_shim(m, ms)) == NULL)
@@ -554,21 +573,25 @@
 }
 
 static struct mbuf *
-mpls_label_inet6(struct mbuf *m, union mpls_shim *ms)
+mpls_label_inet6(struct mbuf *m, union mpls_shim *ms, uint offset)
 {
 	struct ip6_hdr *ip6h;
 
 	if (mpls_mapttl_inet6 || mpls_mapclass_inet6) {
 		if (m->m_len < sizeof(struct ip6_hdr) &&
-		(m = m_pullup(m, sizeof(struct ip6_hdr))) == 0)
+		(m = m_pullup(m, offset + sizeof(struct ip6_hdr))) == 0)
+			return NULL;
+		ip6h = kmem_alloc(sizeof(struct ip6_hdr), KM_NOSLEEP);
+		if (ip6h == NULL)
 			return NULL;
-		ip6h = mtod(m, struct ip6_hdr *);
+		m_copydata(m, offset, sizeof(struct ip6_hdr), ip6h);
 
 		if (mpls_mapttl_inet6)
 			ms->shim.ttl = ip6h->ip6_hlim;
 
 		if (mpls_mapclass_inet6)
 			ms->shim.exp = ip6h->ip6_vfc << 1 >> 5;
+		kmem_free(ip6h, sizeof(struct ip6_hdr));
 	}
 
 	if ((m = mpls_prepend_shim(m, ms)) == NULL)



CVS commit: src/sys/net

2011-06-20 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Mon Jun 20 09:43:27 UTC 2011

Modified Files:
src/sys/net: if_loop.c

Log Message:
Avoid computing INET[6] cksums for MPLS packets


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 src/sys/net/if_loop.c

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

Modified files:

Index: src/sys/net/if_loop.c
diff -u src/sys/net/if_loop.c:1.74 src/sys/net/if_loop.c:1.75
--- src/sys/net/if_loop.c:1.74	Fri Jun 17 09:15:24 2011
+++ src/sys/net/if_loop.c	Mon Jun 20 09:43:27 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_loop.c,v 1.74 2011/06/17 09:15:24 kefren Exp $	*/
+/*	$NetBSD: if_loop.c,v 1.75 2011/06/20 09:43:27 kefren Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.74 2011/06/17 09:15:24 kefren Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.75 2011/06/20 09:43:27 kefren Exp $");
 
 #include "opt_inet.h"
 #include "opt_atalk.h"
@@ -217,7 +217,7 @@
 looutput(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *dst,
 struct rtentry *rt)
 {
-	int s, isr;
+	int s, isr = -1;
 	struct ifqueue *ifq = NULL;
 	int csum_flags;
 
@@ -268,6 +268,19 @@
 
 	m_tag_delete_nonpersistent(m);
 
+#ifdef MPLS
+	if (rt != NULL && rt_gettag(rt) != NULL &&
+	rt_gettag(rt)->sa_family == AF_MPLS &&
+	(m->m_flags & (M_MCAST | M_BCAST)) == 0) {
+		union mpls_shim msh;
+		msh.s_addr = MPLS_GETSADDR(rt);
+		if (msh.shim.label != MPLS_LABEL_IMPLNULL) {
+			ifq = &mplsintrq;
+			isr = NETISR_MPLS;
+		}
+	}
+	if (isr != NETISR_MPLS)
+#endif
 	switch (dst->sa_family) {
 
 #ifdef INET
@@ -320,18 +333,6 @@
 		m_freem(m);
 		return (EAFNOSUPPORT);
 	}
-#ifdef MPLS
-	if (rt != NULL && rt_gettag(rt) != NULL &&
-	rt_gettag(rt)->sa_family == AF_MPLS &&
-	(m->m_flags & (M_MCAST | M_BCAST)) == 0) {
-		union mpls_shim msh;
-		msh.s_addr = MPLS_GETSADDR(rt);
-		if (msh.shim.label != MPLS_LABEL_IMPLNULL) {
-			ifq = &mplsintrq;
-			isr = NETISR_MPLS;
-		}
-	}
-#endif
 	s = splnet();
 	if (IF_QFULL(ifq)) {
 		IF_DROP(ifq);



CVS commit: src/sys/net

2011-06-17 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Fri Jun 17 09:15:24 UTC 2011

Modified Files:
src/sys/net: if_loop.c if_mpls.c

Log Message:
teach loopback about MPLS. Prerequisite for MPLS tunnels


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 src/sys/net/if_loop.c
cvs rdiff -u -r1.4 -r1.5 src/sys/net/if_mpls.c

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

Modified files:

Index: src/sys/net/if_loop.c
diff -u src/sys/net/if_loop.c:1.73 src/sys/net/if_loop.c:1.74
--- src/sys/net/if_loop.c:1.73	Mon Apr 25 22:20:59 2011
+++ src/sys/net/if_loop.c	Fri Jun 17 09:15:24 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_loop.c,v 1.73 2011/04/25 22:20:59 yamt Exp $	*/
+/*	$NetBSD: if_loop.c,v 1.74 2011/06/17 09:15:24 kefren Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -65,13 +65,14 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.73 2011/04/25 22:20:59 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_loop.c,v 1.74 2011/06/17 09:15:24 kefren Exp $");
 
 #include "opt_inet.h"
 #include "opt_atalk.h"
 #include "opt_iso.h"
 #include "opt_ipx.h"
 #include "opt_mbuftrace.h"
+#include "opt_mpls.h"
 
 
 #include 
@@ -117,6 +118,11 @@
 #include 
 #endif
 
+#ifdef MPLS
+#include 
+#include 
+#endif
+
 #ifdef NETATALK
 #include 
 #include 
@@ -314,6 +320,18 @@
 		m_freem(m);
 		return (EAFNOSUPPORT);
 	}
+#ifdef MPLS
+	if (rt != NULL && rt_gettag(rt) != NULL &&
+	rt_gettag(rt)->sa_family == AF_MPLS &&
+	(m->m_flags & (M_MCAST | M_BCAST)) == 0) {
+		union mpls_shim msh;
+		msh.s_addr = MPLS_GETSADDR(rt);
+		if (msh.shim.label != MPLS_LABEL_IMPLNULL) {
+			ifq = &mplsintrq;
+			isr = NETISR_MPLS;
+		}
+	}
+#endif
 	s = splnet();
 	if (IF_QFULL(ifq)) {
 		IF_DROP(ifq);

Index: src/sys/net/if_mpls.c
diff -u src/sys/net/if_mpls.c:1.4 src/sys/net/if_mpls.c:1.5
--- src/sys/net/if_mpls.c:1.4	Thu Jun 16 19:47:31 2011
+++ src/sys/net/if_mpls.c	Fri Jun 17 09:15:24 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_mpls.c,v 1.4 2011/06/16 19:47:31 kefren Exp $ */
+/*	$NetBSD: if_mpls.c,v 1.5 2011/06/17 09:15:24 kefren Exp $ */
 
 /*
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_mpls.c,v 1.4 2011/06/16 19:47:31 kefren Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_mpls.c,v 1.5 2011/06/17 09:15:24 kefren Exp $");
 
 #include "opt_inet.h"
 #include "opt_mpls.h"
@@ -396,11 +396,11 @@
 	}
 
 	switch(ifp->if_type) {
-	/* only these two are supported for now */
+	/* only these are supported for now */
 	case IFT_ETHER:
 	case IFT_TUNNEL:
-		return (*ifp->if_output)(ifp, m, rt->rt_gateway, rt);
 	case IFT_LOOP:
+		return (*ifp->if_output)(ifp, m, rt->rt_gateway, rt);
 		break;
 	default:
 		return ENETUNREACH;



CVS commit: src/usr.sbin/ldpd

2011-06-16 Thread Mihai Chelaru
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/sys/net

2011-06-16 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Thu Jun 16 19:47:31 UTC 2011

Modified Files:
src/sys/net: if_ethersubr.c if_mpls.c

Log Message:
use ETHERTYPE_MPLS only for unicast packets (RFC3032)


To generate a diff of this commit:
cvs rdiff -u -r1.187 -r1.188 src/sys/net/if_ethersubr.c
cvs rdiff -u -r1.3 -r1.4 src/sys/net/if_mpls.c

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

Modified files:

Index: src/sys/net/if_ethersubr.c
diff -u src/sys/net/if_ethersubr.c:1.187 src/sys/net/if_ethersubr.c:1.188
--- src/sys/net/if_ethersubr.c:1.187	Tue May 24 17:16:43 2011
+++ src/sys/net/if_ethersubr.c	Thu Jun 16 19:47:30 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ethersubr.c,v 1.187 2011/05/24 17:16:43 matt Exp $	*/
+/*	$NetBSD: if_ethersubr.c,v 1.188 2011/06/16 19:47:30 kefren Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.187 2011/05/24 17:16:43 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.188 2011/06/16 19:47:30 kefren Exp $");
 
 #include "opt_inet.h"
 #include "opt_atalk.h"
@@ -453,7 +453,8 @@
 
 #ifdef MPLS
 	if (rt0 != NULL && rt_gettag(rt0) != NULL &&
-	rt_gettag(rt0)->sa_family == AF_MPLS) {
+	rt_gettag(rt0)->sa_family == AF_MPLS &&
+	(m->m_flags & (M_MCAST | M_BCAST)) == 0) {
 		union mpls_shim msh;
 		msh.s_addr = MPLS_GETSADDR(rt0);
 		if (msh.shim.label != MPLS_LABEL_IMPLNULL)

Index: src/sys/net/if_mpls.c
diff -u src/sys/net/if_mpls.c:1.3 src/sys/net/if_mpls.c:1.4
--- src/sys/net/if_mpls.c:1.3	Sun Jun 27 13:39:11 2010
+++ src/sys/net/if_mpls.c	Thu Jun 16 19:47:31 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_mpls.c,v 1.3 2010/06/27 13:39:11 kefren Exp $ */
+/*	$NetBSD: if_mpls.c,v 1.4 2011/06/16 19:47:31 kefren Exp $ */
 
 /*
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_mpls.c,v 1.3 2010/06/27 13:39:11 kefren Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_mpls.c,v 1.4 2011/06/16 19:47:31 kefren Exp $");
 
 #include "opt_inet.h"
 #include "opt_mpls.h"
@@ -389,7 +389,8 @@
 	rt->rt_use++;
 
 	msh.s_addr = MPLS_GETSADDR(rt);
-	if (msh.shim.label == MPLS_LABEL_IMPLNULL) {
+	if (msh.shim.label == MPLS_LABEL_IMPLNULL ||
+	(m->m_flags & (M_MCAST | M_BCAST))) {
 		m_adj(m, sizeof(union mpls_shim));
 		m->m_pkthdr.csum_flags = 0;
 	}



CVS commit: src/usr.sbin/ldpd

2011-06-16 Thread Mihai Chelaru
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

2011-06-16 Thread Mihai Chelaru
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_

CVS commit: src/usr.sbin/ldpd

2011-06-16 Thread Mihai Chelaru
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

2011-06-15 Thread Mihai Chelaru
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

2011-06-15 Thread Mihai Chelaru
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

2011-06-15 Thread Mihai Chelaru
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

2011-06-14 Thread Mihai Chelaru
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),
 		l

CVS commit: src/usr.sbin/ldpd

2011-06-14 Thread Mihai Chelaru
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

2011-02-14 Thread Mihai Chelaru
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

2011-02-10 Thread Mihai Chelaru
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/tests/net/route

2011-02-09 Thread Mihai Chelaru
Module Name:src
Committed By:   kefren
Date:   Thu Feb 10 07:47:50 UTC 2011

Modified Files:
src/tests/net/route: t_change.sh

Log Message:
Problem was fixed, don't expect to fail anymore


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/net/route/t_change.sh

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

Modified files:

Index: src/tests/net/route/t_change.sh
diff -u src/tests/net/route/t_change.sh:1.1 src/tests/net/route/t_change.sh:1.2
--- src/tests/net/route/t_change.sh:1.1	Tue Feb  8 10:11:29 2011
+++ src/tests/net/route/t_change.sh	Thu Feb 10 07:47:50 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: t_change.sh,v 1.1 2011/02/08 10:11:29 pooka Exp $
+#	$NetBSD: t_change.sh,v 1.2 2011/02/10 07:47:50 kefren Exp $
 #
 # Copyright (c) 2011 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -47,7 +47,6 @@
 	"rump.route -n show -inet | grep ^207.46"
 	atf_check -s exit:0 -o ignore \
 	rump.route change 207.46.197.32 127.0.0.1 -blackhole
-	atf_expect_fail "PR kern/40455"
 	atf_check -s exit:0 -o match:' UGHBS ' -e ignore \
 	sh -c "rump.netstat -rn -f inet | grep ^207.46| grep ^207.46"
 }



  1   2   >