ospf cost and route selection (openospfd)

Eygene Ryabinkin rea-fbsd at codelabs.ru
Wed Feb 13 11:51:09 PST 2008


Wed, Feb 13, 2008 at 10:37:29PM +0300, Eygene Ryabinkin wrote:
> 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.

Seems like new files/patch-ospfd_packet.c did not get through the
Mailman.  Attaching inline:
-----
--- 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"
 
-int		 ip_hdr_sanity_check(const struct ip *, u_int16_t);
+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 *, 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
-ip_hdr_sanity_check(const struct ip *ip_hdr, u_int16_t len)
+ip_hdr_sanity_check(struct ip *ip_hdr, u_int16_t len)
 {
+#if defined(__NetBSD__) || defined(__FreeBSD__)
+	/* FreeBSD and NetBSD modify the IP header. Undo it! */
+	ip_hdr->ip_len = htons(ip_hdr->ip_len + (ip_hdr->ip_hl << 2));
+#endif
+
 	if (ntohs(ip_hdr->ip_len) != len) {
 		log_debug("recv_packet: invalid IP packet length %u",
 		    ntohs(ip_hdr->ip_len));
-----
-- 
Eygene


More information about the freebsd-net mailing list