Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 13 Feb 2008 22:37:29 +0300
From:      Eygene Ryabinkin <rea-fbsd@codelabs.ru>
To:        Josef Pojsl <jp@tns.cz>
Cc:        freebsd-net@freebsd.org, farrokhi@FreeBSD.org, Claudio Jeker <cjeker@diehard.n-r-g.com>
Subject:   Re: ospf cost and route selection (openospfd)
Message-ID:  <BT4TiDDxXXg%2BA3Hm/RZG4ajuso0@iW7JDlNxJglv8iYoJTWnPBJ0iaQ>
In-Reply-To: <20080208105357.GF1142@bonifac.tns.cz>
References:  <20080206144104.GL1122@bonifac.tns.cz> <jV/l2UkZT%2BCCNuE6npJv1SBs5CE@UCvaDHSF%2BGDEPQ7TSpdR%2BlgUSQM> <20080207074944.GA56085@bonifac.tns.cz> <20080207141422.GG11393@diehard.n-r-g.com> <20080206144104.GL1122@bonifac.tns.cz> <jV/l2UkZT%2BCCNuE6npJv1SBs5CE@UCvaDHSF%2BGDEPQ7TSpdR%2BlgUSQM> <20080207074944.GA56085@bonifac.tns.cz> <Ntfg81bhcEB6BPmKzMb2iTN9oBA@ebJhc%2B9glC7W5vxxBJVH9quBZr0> <BeIqwBu0LkRXuGRr9c834oJe11M@mkgs2gFQr6GPddtmfyJSxMBvIxA> <20080208105357.GF1142@bonifac.tns.cz>

next in thread | previous in thread | raw e-mail | index | archive | help

--Hlh2aiwFLCZwGcpw
Content-Type: text/plain; charset=koi8-r
Content-Disposition: inline

Josef, good day.

Fri, Feb 08, 2008 at 11:53:57AM +0100, Josef Pojsl wrote:
> I did try the patch. Unfortunately, the deamon complains about sending packets
> over gre interfaces. I cannot see any OSPF traffic on them with tcpdump,
> and no routes get added.

Found another OpenBSD/FreeBSD discrepancy: FreeBSD wants to see IP
header's length in the native host order, when it sends the packets
with sendmsg().  Corrected the patch and tried it on my test setup
with Qemu: it worked in the configuration that is simular to yours.
But one exception: my interfaces are not point-to-point, because
it is too late to get VPNs up and running for today ;))  So it will
be very good if you will be able to test the new version.

Attached is the modified patch for the port itself and the modified
file 'files/patch-ospfd_packet.c': it is the only changed file from
the previous version of my patch.  So, if you had already patched
the port to 4.2 with previous version, just drop patch-ospfd_packet.c
into the 'files/' directory and rebuild the patch.

Thanks!
-- 
Eygene

--Hlh2aiwFLCZwGcpw
Content-Type: text/x-diff; charset=koi8-r
Content-Disposition: attachment; filename="4.0-to-4.2.patch"

>From c983b8cc45e3e95991479ae6e213e1ee805c3d91 Mon Sep 17 00:00:00 2001
From: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
Date: Thu, 7 Feb 2008 19:19:54 +0300
Subject: [PATCH] Update ospfd to 4.2.

o Provide LINK_STATE_IS_UP macros that is missing in FreeBSD.
o Disable CARP demotion: FreeBSD has no support for it.
o Disable check for the routing table number: FreeBSD has
  single routing table now.
o Disable route labeling: FreeBSD has no support for it.
o Disable htons() for IP header length: FreeBSD wants it to
  be in the native host order.
o Rewrite old patch for the ospfctl/parser.{c,h}.

Signed-off-by: Eygene Ryabinkin <rea-fbsd@codelabs.ru>
---
 Makefile                     |    3 +-
 distinfo                     |    6 +-
 files/patch-LINK_STATE_IS_UP |   13 ++++
 files/patch-no_carp_demotion |   91 +++++++++++++++++++++++++++
 files/patch-ospfctl_parser   |   59 ++++++++++++++++++
 files/patch-ospfctl_parser.c |   26 --------
 files/patch-ospfctl_parser.h |   26 --------
 files/patch-ospfd_kroute.c   |  138 ++++++++++++++++++++++++++++++++++++------
 files/patch-ospfd_packet.c   |   23 ++++++--
 9 files changed, 304 insertions(+), 81 deletions(-)
 create mode 100644 files/patch-LINK_STATE_IS_UP
 create mode 100644 files/patch-no_carp_demotion
 create mode 100644 files/patch-ospfctl_parser
 delete mode 100644 files/patch-ospfctl_parser.c
 delete mode 100644 files/patch-ospfctl_parser.h

diff --git a/Makefile b/Makefile
index 4423454..777f71b 100644
--- a/Makefile
+++ b/Makefile
@@ -6,8 +6,7 @@
 #
 
 PORTNAME=	openospfd
-PORTVERSION=	4.0
-PORTREVISION=	2
+PORTVERSION=	4.2
 CATEGORIES=	net
 MASTER_SITES=	ftp://ftp.dkuug.dk/pub/OpenBSD/OpenBGPD/:openbsd \
 		${MASTER_SITE_LOCAL:S/$/:freebsd/g}
diff --git a/distinfo b/distinfo
index 84810c8..bf2bc20 100644
--- a/distinfo
+++ b/distinfo
@@ -1,6 +1,6 @@
-MD5 (openospfd/openospfd-4.0.tgz) = 6dcf9170627120f009ff9d5917b49376
-SHA256 (openospfd/openospfd-4.0.tgz) = c9e87e849664a6674a4a650a453754b53d6c0bd1110ee5e82a7b6cc7fbad6ee7
-SIZE (openospfd/openospfd-4.0.tgz) = 84459
+MD5 (openospfd/openospfd-4.2.tgz) = ac919e4883105b28a846106e7c60bb80
+SHA1 (openospfd/openospfd-4.2.tgz) = ebb476d834d3aa5ddc3a5e96ea2f494f2617c393
+SIZE (openospfd/openospfd-4.2.tgz) = 93661
 MD5 (openospfd/if_media.h) = 4ff9297f5c133425dafe3ca565c0f811
 SHA256 (openospfd/if_media.h) = 58225d0ed363c2beb23426f0f8254089d4541c3334776f3750ba434d4491a1d1
 SIZE (openospfd/if_media.h) = 23762
diff --git a/files/patch-LINK_STATE_IS_UP b/files/patch-LINK_STATE_IS_UP
new file mode 100644
index 0000000..bcd1f6d
--- /dev/null
+++ b/files/patch-LINK_STATE_IS_UP
@@ -0,0 +1,13 @@
+--- ospfd/ospfd.h.orig	2008-02-07 18:57:03.000000000 +0300
++++ ospfd/ospfd.h	2008-02-07 18:56:54.000000000 +0300
+@@ -320,6 +320,10 @@
+ TAILQ_HEAD(lsa_head, lsa_entry);
+ TAILQ_HEAD(auth_md_head, auth_md);
+ 
++#if defined(__FreeBSD__) /* FreeBSD has no LINK_STATE_IS_UP macro. */
++#define LINK_STATE_IS_UP(_s)	((_s) >= LINK_STATE_UP)
++#endif /* defined(__FreeBSD__) */
++
+ struct iface {
+ 	LIST_ENTRY(iface)	 entry;
+ 	struct event		 hello_timer;
diff --git a/files/patch-no_carp_demotion b/files/patch-no_carp_demotion
new file mode 100644
index 0000000..2882279
--- /dev/null
+++ b/files/patch-no_carp_demotion
@@ -0,0 +1,91 @@
+--- ospfd/ospfd.c.orig	2008-02-07 18:31:27.000000000 +0300
++++ ospfd/ospfd.c	2008-02-07 18:41:46.000000000 +0300
+@@ -300,7 +300,9 @@
+ 
+ 	control_cleanup();
+ 	kr_shutdown();
++#if !defined(__FreeBSD__) /* XXX: FreeBSD has no carp demotion. */
+ 	carp_demote_shutdown();
++#endif /* defined(__FreeBSD__) */
+ 
+ 	do {
+ 		if ((pid = wait(NULL)) == -1 &&
+@@ -398,10 +400,14 @@
+ 				log_warnx("IFINFO request with wrong len");
+ 			break;
+ 		case IMSG_DEMOTE:
++#if !defined(__FreeBSD__) /* XXX: FreeBSD has no carp demotion support. */
+ 			if (imsg.hdr.len - IMSG_HEADER_SIZE != sizeof(dmsg))
+ 				fatalx("invalid size of OE request");
+ 			memcpy(&dmsg, imsg.data, sizeof(dmsg));
+ 			carp_demote_set(dmsg.demote_group, dmsg.level);
++#else
++			log_debug("main_dispatch_ospfe: no carp demotion support for FreeBSD");
++#endif /* defined(__FreeBSD__) */
+ 			break;
+ 		default:
+ 			log_debug("main_dispatch_ospfe: error handling imsg %d",
+--- ospfd/carp.c.orig	2008-02-07 18:26:32.000000000 +0300
++++ ospfd/carp.c	2008-02-07 18:39:58.000000000 +0300
+@@ -29,6 +29,13 @@
+ #include "ospfd.h"
+ #include "log.h"
+ 
++#if defined(__FreeBSD__) /* XXX: FreeBSD has no CARP demotion support */
++
++#warning "CARP demotion is not supported for FreeBSD."
++#warning "Demotion code is disconnected from the build."
++
++#else
++
+ struct carpgroup {
+ 	TAILQ_ENTRY(carpgroup)	 entry;
+ 	char			*group;
+@@ -179,3 +186,5 @@
+ 	close(s);
+ 	return (res);
+ }
++
++#endif /* defined(__FreeBSD__) */
+--- ospfd/parse.y.orig	2008-02-07 18:34:22.000000000 +0300
++++ ospfd/parse.y	2008-02-07 18:37:46.000000000 +0300
+@@ -485,6 +485,11 @@
+ 
+ areaoptsl	: interface
+ 		| DEMOTE STRING	demotecount {
++#ifdef __FreeBSD__ /* XXX: FreeBSD has no carp demotion support. */
++			yyerror("FreeBSD has no CARP demotion support");
++			free($2);
++			YYERROR;
++#else
+ 			if ($3 > 255) {
+ 				yyerror("demote count too big: max 255");
+ 				free($2);
+@@ -505,6 +510,7 @@
+ 				    area->demote_group);
+ 				YYERROR;
+ 			}
++#endif
+ 		}
+ 		| defaults
+ 		;
+@@ -581,6 +587,11 @@
+ 
+ interfaceoptsl	: PASSIVE		{ iface->passive = 1; }
+ 		| DEMOTE STRING		{
++#ifdef __FreeBSD__ /* XXX: FreeBSD has no carp demotion support */
++			yyerror("FreeBSD has no CARP demotion support");
++			free($2);
++			YYERROR;
++#else
+ 			if (strlcpy(iface->demote_group, $2,
+ 			    sizeof(iface->demote_group)) >=
+ 			    sizeof(iface->demote_group)) {
+@@ -595,6 +606,7 @@
+ 				    iface->demote_group);
+ 				YYERROR;
+ 			}
++#endif
+ 		}
+ 		| defaults
+ 		;
diff --git a/files/patch-ospfctl_parser b/files/patch-ospfctl_parser
new file mode 100644
index 0000000..1d0a82c
--- /dev/null
+++ b/files/patch-ospfctl_parser
@@ -0,0 +1,59 @@
+--- ospfctl/parser.c.orig	2008-02-07 19:13:50.000000000 +0300
++++ ospfctl/parser.c	2008-02-07 19:15:47.000000000 +0300
+@@ -32,23 +32,6 @@
+ 
+ #include "parser.h"
+ 
+-enum token_type {
+-	NOTOKEN,
+-	ENDTOKEN,
+-	KEYWORD,
+-	ADDRESS,
+-	FLAG,
+-	PREFIX,
+-	IFNAME
+-};
+-
+-struct token {
+-	enum token_type		 type;
+-	const char		*keyword;
+-	int			 value;
+-	const struct token	*next;
+-};
+-
+ static const struct token t_main[];
+ static const struct token t_fib[];
+ static const struct token t_show[];
+--- ospfctl/parser.h.orig	2008-02-07 19:12:58.000000000 +0300
++++ ospfctl/parser.h	2008-02-07 19:15:45.000000000 +0300
+@@ -50,6 +50,16 @@
+ 	RELOAD
+ };
+ 
++enum token_type {
++	NOTOKEN,
++	ENDTOKEN,
++	KEYWORD,
++	ADDRESS,
++	FLAG,
++	PREFIX,
++	IFNAME
++};
++
+ struct parse_result {
+ 	struct in_addr	addr;
+ 	char		ifname[IF_NAMESIZE];
+@@ -58,6 +68,13 @@
+ 	u_int8_t	prefixlen;
+ };
+ 
++struct token {
++	enum token_type		 type;
++	const char		*keyword;
++	int			 value;
++	const struct token	*next;
++};
++
+ struct parse_result	*parse(int, char *[]);
+ const struct token	*match_token(const char *, const struct token []);
+ void			 show_valid_args(const struct token []);
diff --git a/files/patch-ospfctl_parser.c b/files/patch-ospfctl_parser.c
deleted file mode 100644
index c4f7fc8..0000000
--- a/files/patch-ospfctl_parser.c
+++ /dev/null
@@ -1,26 +0,0 @@
---- ospfctl/parser.c.orig	Fri Jul 27 15:11:46 2007
-+++ ospfctl/parser.c	Fri Jul 27 15:12:01 2007
-@@ -32,23 +32,6 @@
- 
- #include "parser.h"
- 
--enum token_type {
--	NOTOKEN,
--	ENDTOKEN,
--	KEYWORD,
--	ADDRESS,
--	FLAG,
--	PREFIX,
--	IFNAME
--};
--
--struct token {
--	enum token_type		 type;
--	const char		*keyword;
--	int			 value;
--	const struct token	*next;
--};
--
- static const struct token t_main[];
- static const struct token t_fib[];
- static const struct token t_show[];
diff --git a/files/patch-ospfctl_parser.h b/files/patch-ospfctl_parser.h
deleted file mode 100644
index b4eab49..0000000
--- a/files/patch-ospfctl_parser.h
+++ /dev/null
@@ -1,26 +0,0 @@
---- ospfctl/parser.h.orig	Fri Jul 27 15:11:55 2007
-+++ ospfctl/parser.h	Fri Jul 27 15:12:01 2007
-@@ -50,6 +50,23 @@
- 	RELOAD
- };
- 
-+enum token_type {
-+	NOTOKEN,
-+	ENDTOKEN,
-+	KEYWORD,
-+	ADDRESS,
-+	FLAG,
-+	PREFIX,
-+	IFNAME
-+};
-+
-+struct token {
-+	enum token_type		 type;
-+	const char		*keyword;
-+	int			 value;
-+	const struct token	*next;
-+};
-+
- struct parse_result {
- 	struct in_addr	addr;
- 	char		ifname[IF_NAMESIZE];
diff --git a/files/patch-ospfd_kroute.c b/files/patch-ospfd_kroute.c
index 6415a3b..2b1bd77 100644
--- a/files/patch-ospfd_kroute.c
+++ b/files/patch-ospfd_kroute.c
@@ -1,36 +1,136 @@
---- ospfd/kroute.c.orig	Mon Nov 20 14:41:22 2006
-+++ ospfd/kroute.c	Mon Nov 20 14:42:17 2006
-@@ -875,10 +875,6 @@
+--- ospfd/kroute.c.orig	2008-02-07 18:58:38.000000000 +0300
++++ ospfd/kroute.c	2008-02-07 19:09:58.000000000 +0300
+@@ -955,9 +955,11 @@
+ 	struct sockaddr_in	prefix;
+ 	struct sockaddr_in	nexthop;
+ 	struct sockaddr_in	mask;
++#if !defined(__FreeBSD__)
+ 	struct sockaddr_rtlabel	sa_rl;
+-	int			iovcnt = 0;
+ 	const char		*label;
++#endif /* !defined(__FreeBSD__) */
++	int			iovcnt = 0;
+ 
+ 	if (kr_state.fib_sync == 0)
+ 		return (0);
+@@ -1011,6 +1013,7 @@
+ 	iov[iovcnt].iov_base = &mask;
+ 	iov[iovcnt++].iov_len = sizeof(mask);
+ 
++#if !defined(__FreeBSD__) /* FreeBSD has no route labeling. */
+ 	if (kroute->rtlabel != 0) {
+ 		sa_rl.sr_len = sizeof(sa_rl);
+ 		sa_rl.sr_family = AF_UNSPEC;
+@@ -1027,6 +1030,7 @@
+ 		iov[iovcnt].iov_base = &sa_rl;
+ 		iov[iovcnt++].iov_len = sizeof(sa_rl);
+ 	}
++#endif /* !defined(__FreeBSD__) */
+ 
+ 
+ retry:
+@@ -1069,7 +1073,9 @@
+ 	struct rt_msghdr	*rtm;
+ 	struct sockaddr		*sa, *rti_info[RTAX_MAX];
+ 	struct sockaddr_in	*sa_in;
++#if !defined(__FreeBSD__)
+ 	struct sockaddr_rtlabel	*label;
++#endif
+ 	struct kroute_node	*kr;
+ 
+ 	mib[0] = CTL_NET;
+@@ -1078,9 +1084,13 @@
+ 	mib[3] = AF_INET;
+ 	mib[4] = NET_RT_DUMP;
+ 	mib[5] = 0;
++#if !defined(__FreeBSD__) /* FreeBSD has no multiple routing tables */
+ 	mib[6] = 0;	/* rtableid */
+ 
+ 	if (sysctl(mib, 7, NULL, &len, NULL, 0) == -1) {
++#else
++	if (sysctl(mib, 6, NULL, &len, NULL, 0) == -1) {
++#endif /* !defined(__FreeBSD__) */
+ 		log_warn("sysctl");
+ 		return (-1);
+ 	}
+@@ -1098,7 +1098,11 @@
+ 		log_warn("fetchtable");
+ 		return (-1);
+ 	}
++#if !defined(__FreeBSD__) /* FreeBSD has no multiple routing tables */
+ 	if (sysctl(mib, 7, buf, &len, NULL, 0) == -1) {
++#else
++	if (sysctl(mib, 6, buf, &len, NULL, 0) == -1) {
++#endif /* !defined(__FreeBSD__) */
+ 		log_warn("sysctl");
+ 		free(buf);
+ 		return (-1);
+@@ -1157,6 +1163,7 @@
  			send_rtmsg(kr_state.fd, RTM_DELETE, &kr->r);
  			free(kr);
  		} else {
--			if ((label = (struct sockaddr_rtlabel *)
--			    rti_info[RTAX_LABEL]) != NULL)
--				kr->r.rtlabel =
--				    rtlabel_name2id(label->sr_label);
++#if !defined(__FreeBSD__) /* FreeBSD has no route labeling. */
+ 			if ((label = (struct sockaddr_rtlabel *)
+ 			    rti_info[RTAX_LABEL]) != NULL) {
+ 				kr->r.rtlabel =
+@@ -1164,6 +1171,7 @@
+ 				kr->r.ext_tag =
+ 				    rtlabel_id2tag(kr->r.rtlabel);
+ 			}
++#endif /* !defined(__FreeBSD__) */
  			kroute_insert(kr);
  		}
  
-@@ -1075,10 +1071,6 @@
+@@ -1257,7 +1265,9 @@
+ 	struct ifa_msghdr	*ifam;
+ 	struct sockaddr		*sa, *rti_info[RTAX_MAX];
+ 	struct sockaddr_in	*sa_in;
++#if !defined(__FreeBSD__)
+ 	struct sockaddr_rtlabel	*label;
++#endif /* !defined(__FreeBSD__) */
+ 	struct kroute_node	*kr, *okr;
+ 	struct in_addr		 prefix, nexthop;
+ 	u_int8_t		 prefixlen;
+@@ -1289,8 +1299,10 @@
+ 			sa = (struct sockaddr *)(rtm + 1);
+ 			get_rtaddrs(rtm->rtm_addrs, sa, rti_info);
  
++#if !defined(__FreeBSD__) /* XXX: FreeBSD has no multiple routing tables */
+ 			if (rtm->rtm_tableid != 0)
+ 				continue;
++#endif
+ 
+ 			if (rtm->rtm_pid == kr_state.pid) /* caused by us */
+ 				continue;
+@@ -1385,6 +1397,7 @@
  				rtlabel_unref(kr->r.rtlabel);
  				kr->r.rtlabel = 0;
--				if ((label = (struct sockaddr_rtlabel *)
--				    rti_info[RTAX_LABEL]) != NULL)
--					kr->r.rtlabel =
--					    rtlabel_name2id(label->sr_label);
+ 				kr->r.ext_tag = 0;
++#if !defined(__FreeBSD__) /* FreeBSD has no route labeling. */
+ 				if ((label = (struct sockaddr_rtlabel *)
+ 				    rti_info[RTAX_LABEL]) != NULL) {
+ 					kr->r.rtlabel =
+@@ -1392,6 +1405,7 @@
+ 					kr->r.ext_tag =
+ 					    rtlabel_id2tag(kr->r.rtlabel);
+ 				}
++#endif /* !defined(__FreeBSD__) */
  
  				if (kif_validate(kr->r.ifindex))
  					kr->r.flags &= ~F_DOWN;
-@@ -1098,11 +1090,6 @@
- 				kr->r.nexthop.s_addr = nexthop.s_addr;
+@@ -1413,6 +1427,7 @@
  				kr->r.flags = flags;
  				kr->r.ifindex = ifindex;
--
--				if ((label = (struct sockaddr_rtlabel *)
--				    rti_info[RTAX_LABEL]) != NULL)
--					kr->r.rtlabel =
--					    rtlabel_name2id(label->sr_label);
+ 
++#if !defined(__FreeBSD__) /* FreeBSD has no route labeling */
+ 				if ((label = (struct sockaddr_rtlabel *)
+ 				    rti_info[RTAX_LABEL]) != NULL) {
+ 					kr->r.rtlabel =
+@@ -1420,6 +1435,7 @@
+ 					kr->r.ext_tag =
+ 					    rtlabel_id2tag(kr->r.rtlabel);
+ 				}
++#endif /* !defined(__FreeBSD__) */
  
  				kroute_insert(kr);
  			}
diff --git a/files/patch-ospfd_packet.c b/files/patch-ospfd_packet.c
index 414554a..cceb302 100644
--- a/files/patch-ospfd_packet.c
+++ b/files/patch-ospfd_packet.c
@@ -1,6 +1,6 @@
---- ospfd/packet.c.orig	9 Mar 2006 13:31:57 -0000	1.20
-+++ ospfd/packet.c	16 Mar 2006 18:21:38 -0000
-@@ -34,7 +34,7 @@
+--- ospfd/packet.c.orig	2006-11-17 11:55:31.000000000 +0300
++++ ospfd/packet.c	2008-02-13 22:13:04.000000000 +0300
+@@ -36,7 +36,7 @@
  #include "log.h"
  #include "ospfe.h"
  
@@ -8,8 +8,21 @@
 +int		 ip_hdr_sanity_check(struct ip *, u_int16_t);
  int		 ospf_hdr_sanity_check(const struct ip *,
  		    struct ospf_hdr *, u_int16_t, const struct iface *);
- struct iface	*find_iface(struct ospfd_conf *, struct in_addr);
-@@ -196,8 +196,13 @@ recv_packet(int fd, short event, void *b
+ struct iface	*find_iface(struct ospfd_conf *, unsigned int, struct in_addr);
+@@ -70,7 +70,12 @@
+ 	ip_hdr.ip_v = IPVERSION;
+ 	ip_hdr.ip_hl = sizeof(ip_hdr) >> 2;
+ 	ip_hdr.ip_tos = IPTOS_PREC_INTERNETCONTROL;
++#if defined(__FreeBSD__) || defined(__NetBSD__)
++	/* FreeBSD/NetBSD wants the length in the native host byte order. */
++	ip_hdr.ip_len = len + sizeof(ip_hdr);
++#else
+ 	ip_hdr.ip_len = htons(len + sizeof(ip_hdr));
++#endif
+ 	ip_hdr.ip_id = 0;  /* 0 means kernel set appropriate value */
+ 	ip_hdr.ip_off = 0;
+ 	ip_hdr.ip_ttl = iface->type != IF_TYPE_VIRTUALLINK ?
+@@ -248,8 +253,13 @@
  }
  
  int
-- 
1.5.3.8


--Hlh2aiwFLCZwGcpw--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?BT4TiDDxXXg%2BA3Hm/RZG4ajuso0>