OSPF HELLO wrong mask

Alexander V. Chernikov melifaro at yandex-team.ru
Fri May 17 17:13:50 CEST 2013


On 15.05.2013 21:18, Slawa Olhovchenkov wrote:
> On Wed, May 15, 2013 at 07:29:04PM +0200, Ondrej Zajicek wrote:
>
>> On Wed, May 15, 2013 at 08:33:08PM +0400, Slawa Olhovchenkov wrote:
>>>> Interesting
>>>> What 'show interfaces' and 'show ospf interface' return?
>>>> And also 'show status' for router id.
>>> ifconfig em0 (full)
>>> em0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
>>>          options=4219b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,TSO4,WOL_MAGIC,VLAN_HWTSO>
>>>          ether 68:05:ca:0e:d3:e1
>>>          inet 10.254.0.2 netmask 0xffff0000 broadcast 10.254.255.255
>>>          inet6 fe80::6a05:caff:fe0e:d3e1%em0 prefixlen 64 scopeid 0x1
>>>          inet 185.17.0.1 netmask 0xffffff00 broadcast 185.17.0.255
>>>          inet 185.17.1.1 netmask 0xffffff00 broadcast 185.17.1.255
>>>          inet6 2a03:e2c0:0:1::1 prefixlen 64
>>>          inet 185.17.2.1 netmask 0xffffff00 broadcast 185.17.2.255
>>>          inet 185.17.3.1 netmask 0xffffff00 broadcast 185.17.3.255
>>>          inet 10.90.90.1 netmask 0xfffffff0 broadcast 10.90.90.15
>>>          inet 193.93.192.1 netmask 0xfffffc00 broadcast 193.93.195.255
>>>          nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
>>>          media: Ethernet autoselect (1000baseT <full-duplex>)
>>>          status: active
>> So this is a problem with multiple IPs on an iface. On BSD, we support
>> just one primary address in OSPF (others are just handled as stubs).
>> Lexicographically smallest address was chosen. Unfortunately the kernel
>> chose a different one as a source address.
> Why lexicographically smallest?
> Why not first from getifaddrs() list?
I've got the following patch, which works for CARP instances, and should 
work in your case.

>
>> If you use multiple IPs on an iface in BSD with BIRD, you have to
>> use option 'primary' of device protocol to specify the proper one:
>> http://bird.network.cz/?get_doc&f=bird-6.html#ss6.2
> 10x, working.
>

-------------- next part --------------
diff --git a/sysdep/bsd/krt-sock.c b/sysdep/bsd/krt-sock.c
index e970d6b..202255e 100644
--- a/sysdep/bsd/krt-sock.c
+++ b/sysdep/bsd/krt-sock.c
@@ -594,6 +594,45 @@ krt_read_addr(struct ks_msg *msg)
     ifa_delete(&ifa);
 }
 
+#ifndef IPV6
+struct ifa *
+kif_get_primary_ip(struct iface *i)
+{
+  struct ifreq ifr;
+  int fd, res;
+  struct sockaddr_in *sin;
+  ip_addr addr = IPA_NONE;
+  struct ifa *a = NULL;
+
+  fd = socket(AF_INET, SOCK_DGRAM, 0);
+
+  if (fd == -1)
+    return NULL;
+
+  memset(&ifr, 0, sizeof(ifr));
+
+  strcpy(ifr.ifr_name, i->name);
+
+  res = ioctl(fd, SIOCGIFADDR, (char *)&ifr);
+  close(fd);
+
+  if (res == -1)
+    return NULL;
+
+  sin = (struct sockaddr_in *)&ifr.ifr_addr;
+  memcpy(&addr, &sin->sin_addr, sizeof(ip_addr));
+  ipa_ntoh(addr);
+
+  WALK_LIST(a, i->addrs)
+    {
+      if (a->ip == addr)
+	return a;
+    }
+
+  return NULL;
+}
+#endif
+
 
 void
 krt_read_msg(struct proto *p, struct ks_msg *msg, int scan)
diff --git a/sysdep/unix/krt.c b/sysdep/unix/krt.c
index 3761ace..1fc4345 100644
--- a/sysdep/unix/krt.c
+++ b/sysdep/unix/krt.c
@@ -157,6 +157,9 @@ kif_choose_primary(struct iface *i)
 	  return a;
     }
 
+  if (a = kif_get_primary_ip(i))
+    return a;
+
   return find_preferred_ifa(i, IPA_NONE, IPA_NONE);
 }
 
diff --git a/sysdep/unix/krt.h b/sysdep/unix/krt.h
index d6fbf72..3a037e3 100644
--- a/sysdep/unix/krt.h
+++ b/sysdep/unix/krt.h
@@ -78,6 +78,8 @@ void kif_request_scan(void);
 void krt_got_route(struct krt_proto *p, struct rte *e);
 void krt_got_route_async(struct krt_proto *p, struct rte *e, int new);
 
+struct ifa *kif_get_primary_ip(struct iface *i);
+
 /* Values for rte->u.krt_sync.src */
 #define KRT_SRC_UNKNOWN	-1	/* Nobody knows */
 #define KRT_SRC_BIRD	 0	/* Our route (not passed in async mode) */


More information about the Bird-users mailing list