]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Temoporary OSPF commit - socket changes.
authorOndrej Zajicek <santiago@crfreenet.org>
Thu, 11 Mar 2010 17:07:24 +0000 (18:07 +0100)
committerOndrej Zajicek <santiago@crfreenet.org>
Thu, 11 Mar 2010 17:07:24 +0000 (18:07 +0100)
nest/iface.h
proto/ospf/dbdes.c
proto/ospf/hello.c
proto/ospf/iface.c
proto/ospf/lsack.c
proto/ospf/lsreq.c
proto/ospf/lsupd.c
proto/ospf/packet.c
proto/ospf/packet.h

index a982c17f4bf370fc4e6a7f07b400b15702271b13..b7c3c19c0b5831eda12720758ab11a489bcd87aa 100644 (file)
@@ -82,6 +82,15 @@ struct iface *if_find_by_index(unsigned);
 struct iface *if_find_by_name(char *);
 void ifa_recalc_all_primary_addresses(void);
 
+static inline int
+ifa_match_addr(struct ifa *ifa, ip_addr addr)
+{
+  if (ifa->flags & IA_UNNUMBERED)
+    return ipa_equal(addr, ifa->opposite);
+  else
+    return ipa_in_net(addr, ifa->prefix, ifa->pxlen);
+}
+
 /* The Neighbor Cache */
 
 typedef struct neighbor {
index 9f126821459b1ec94c25538935447ff878ac8073..8cd7c8b2732b5ffde6678b15ad0110ac979e6b2c 100644 (file)
@@ -93,7 +93,7 @@ ospf_dbdes_send(struct ospf_neighbor *n, int next)
   {
   case NEIGHBOR_EXSTART:       /* Send empty packets */
     n->myimms.bit.i = 1;
-    pkt = ospf_tx_buffer();
+    pkt = ospf_tx_buffer(ifa);
     op = &pkt->ospf_packet;
     ospf_pkt_fill_hdr(ifa, pkt, DBDES_P);
     pkt->iface_mtu = htons(ifa->iface->mtu);
@@ -185,7 +185,7 @@ ospf_dbdes_send(struct ospf_neighbor *n, int next)
     }
 
     /* Copy last sent packet again */
-    pkt = ospf_tx_buffer();
+    pkt = ospf_tx_buffer(ifa);
     memcpy(pkt, n->ldbdes, length);
 
     OSPF_PACKET(ospf_dump_dbdes, pkt, "DBDES packet sent to %I via %s", n->ip, ifa->iface->name);
index eaf7d2306de5bef369b1fa1223fca272b070b711..9f174df81f670565f82510e39f65d2ee51a013f8 100644 (file)
@@ -258,7 +258,7 @@ ospf_hello_send(timer *timer, int poll, struct ospf_neighbor *dirn)
       p->name, ifa->iface->name);
 
   /* Now we should send a hello packet */
-  pkt = ospf_tx_buffer();
+  pkt = ospf_tx_buffer(ifa);
   op = &pkt->ospf_packet;
 
   /* Now fill ospf_hello header */
index 3f1e74dca9219e52ba3a40d34fa94098d2c07931..a99ceb12fbeafc6d9b1ede87f28a21931f400832 100644 (file)
@@ -82,9 +82,6 @@ ospf_sk_open(struct ospf_iface *ifa, int mc)
 #endif
 
   sk->tos = IP_PREC_INTERNET_CONTROL;
-  sk->ttl = 1;
-  if (ifa->type == OSPF_IT_VLINK)
-    sk->ttl = 255;
   sk->rx_hook = ospf_rx_hook;
   sk->tx_hook = ospf_tx_hook;
   sk->err_hook = ospf_err_hook;
@@ -191,10 +188,12 @@ ospf_iface_chstate(struct ospf_iface *ifa, u8 state)
       OSPF_TRACE(D_EVENTS,
                 "Changing state of virtual link %R from \"%s\" into \"%s\".",
                 ifa->vid, ospf_is[oldstate], ospf_is[state]);
+      /*
       if (state == OSPF_IS_PTP)
        ospf_sk_open(ifa, 0);
       if (state == OSPF_IS_DOWN)
        ospf_sk_close(ifa);
+      */
     }
     else
     {
index 73d79a278806c09c20c7167bde850d6ac0b33a90..c05f019619c2fa5035adb6be916e5311804a337d 100644 (file)
@@ -66,7 +66,7 @@ ospf_lsack_send(struct ospf_neighbor *n, int queue)
   if (EMPTY_LIST(n->ackl[queue]))
     return;
 
-  pk = ospf_tx_buffer();
+  pk = ospf_tx_buffer(ifa);
   op = &pk->ospf_packet;
 
   ospf_pkt_fill_hdr(n->ifa, pk, LSACK_P);
index b61e0ce5b73dc9da35f2a1025b334f16d4bc4857..1ba4fff9314ef3fefc98b675051c288cecaea77a 100644 (file)
@@ -44,7 +44,7 @@ ospf_lsreq_send(struct ospf_neighbor *n)
   int i, j;
   struct proto *p = &n->ifa->oa->po->proto;
 
-  pk = ospf_tx_buffer();
+  pk = ospf_tx_buffer(n->ifa);
   op = &pk->ospf_packet;
 
   ospf_pkt_fill_hdr(n->ifa, pk, LSREQ_P);
index 133a036d0f629469e7c3a3f0139ca02505781244..39d91b9a74b5b8c1bb57ca801129cfa585a70426 100644 (file)
@@ -269,7 +269,7 @@ ospf_lsupd_flood(struct proto_ospf *po,
       struct ospf_packet *op;
       struct ospf_lsa_header *lh;
 
-      pk = ospf_tx_buffer();
+      pk = ospf_tx_buffer(ifa);
       op = &pk->ospf_packet;
 
       ospf_pkt_fill_hdr(ifa, pk, LSUPD_P);
@@ -350,7 +350,7 @@ ospf_lsupd_send_list(struct ospf_neighbor *n, list * l)
 
   DBG("LSupd: 1st packet\n");
 
-  pk= ospf_tx_buffer();
+  pk= ospf_tx_buffer(n->ifa);
   op = &pk->ospf_packet;
 
   ospf_pkt_fill_hdr(n->ifa, pk, LSUPD_P);
index 81686d25cf1ff78a9f15e0506b361ad5c80e5f48..6697057bdae541c55a11a3b606b66e890764ffad 100644 (file)
@@ -255,55 +255,6 @@ ospf_pkt_checkauth(struct ospf_neighbor *n, struct ospf_iface *ifa, struct ospf_
  
 #endif
 
-static struct ospf_iface *
-find_matching_iface(struct ospf_packet *ps, unsigned ifindex, ip_addr faddr)
-{
-  u32 areaid = ntohl(ps->areaid);
-  u32 rid = ntohl(ps->routerid);
-  node *nd;
-
-  /* First, we will try to match real ifaces */
-
-  WALK_LIST(nd, ospf_ifaces)
-    {
-      struct ospf_iface *ifa = SKIP_BACK(struct ospf_iface, sk_node, nd);
-      struct ifa *addr = ifa->addr;
-
-      if ((ifa->iface->index == ifindex) &&
-         (ifa->oa->areaid == areaid) && 
-#ifdef OSPFv2
-         ((addr->flags & IA_UNNUMBERED) ?
-          ipa_equal(faddr, addr->opposite) :
-          ipa_in_net(faddr, addr->prefix, addr->pxlen))
-#else /* OSPFv3 */
-         (ifa->instance_id == ps->instance_id)
-#endif
-         )
-       return ifa;
-    }
-
-  /* Second, we will try to match vlinks */
-
-  if (areaid != 0)
-    return NULL;
-
-  /* FIXME: There should be some more checks to distinquish parallel
-     vlinks to the same ABR. */
-
-  WALK_LIST(nd, ospf_vlinks)
-    {
-      struct ospf_iface *ifa = SKIP_BACK(struct ospf_iface, sk_node, nd);
-
-      if ((ifa->vid == rid)
-#ifdef OSPFv3
-         && (ifa->instance_id == ps->instance_id)
-#endif
-         )
-       return ifa;
-    }
-
-  return NULL;
-}
 
 /**
  * ospf_rx_hook
@@ -319,9 +270,47 @@ ospf_rx_hook(sock *sk, int size)
 {
   char *mesg = "OSPF: Bad packet from ";
 
-  DBG("OSPF: RX_Hook called (from %I)\n", sk->faddr);
+  /* We want just packets from sk->iface. Unfortunately, on BSD we
+     cannot filter out other packets at kernel level and we receive
+     all packets on all sockets */
+  if (sk->lifindex != sk->iface->index)
+    return 1;
+
+  DBG("OSPF: RX hook called (iface %s, src %I, dst %I)\n",
+      sk->iface->name, sk->faddr, sk->laddr);
+
+  /* Initially, the packet is associated with the 'master' iface */
+  struct ospf_iface *ifa = sk->data;
+  struct proto_ospf *po = ifa->oa->po;
+  struct proto *p = &po->proto;
+
+  int src_local = ifa_match_addr(ifa->addr, sk->faddr);
+  int dst_local = ipa_equal(sk->laddr, ifa->addr->ip);
+  int dst_mcast = ipa_equal(sk->laddr, AllSPFRouters) || ipa_equal(sk->laddr, AllDRouters);
+
+#ifdef OSPFv2
+  /* First, we eliminate packets with strange address combinations.
+   * In OSPFv2, they might be for other ospf_ifaces (with different IP
+   * prefix) on the same real iface, so we don't log it. We enforce
+   * that (src_local || dst_local), therefore we are eliminating all
+   * such cases. 
+   */
+  if (dst_mcast && !src_local)
+    return 1;
+  if (!dst_mcast && !dst_local)
+    return 1;
 
-  /* First, we check packet size, checksum, and the protocol version */
+#else /* OSPFv3 */
+
+  /* In OSPFv3, src_local and dst_local mean link-local. 
+   * RFC 5340 says that local (non-vlink) packets use
+   * link-local src address, but does not enforce it. Strange.
+   */
+  if (dst_mcast && !src_local)
+    log(L_WARN "OSPF: Received multicast packet from %I (not link-local)", sk->faddr);
+#endif
+
+  /* Second, we check packet size, checksum, and the protocol version */
   struct ospf_packet *ps = (struct ospf_packet *) ip_skip_header(sk->rbuf, &size);
 
   if (ps == NULL)
@@ -366,38 +355,78 @@ ospf_rx_hook(sock *sk, int size)
 #endif
 
 
-  /* Now, we would like to associate the packet with an OSPF iface */
-  struct ospf_iface *ifa = find_matching_iface(ps, sk->lifindex, sk->faddr);
-  if (ifa == NULL)
+  /* Third, we resolve associated iface and handle vlinks. */
+
+  u32 areaid = ntohl(ps->areaid);
+  u32 rid = ntohl(ps->routerid);
+
+  if ((areaid == ifa->oa->areaid)
+#ifdef OSPFv3
+      && (ps->instance_id != ifa->instance_id)
+#endif
+      )
+  {
+    /* It is real iface, source should be local (in OSPFv2) */
+#ifdef OSPFv2
+    if (!src_local)
+      return 1;
+#endif
+  }
+  else if (dst_mcast || (areaid != 0))
+  {
+    /* Obvious mismatch */
+
+#ifdef OSPFv2
+    /* We ignore mismatch in OSPFv3, because there might be
+       other instance with different instance ID */
+    log(L_ERR "%s%I - area does not match (%R vs %R)",
+       mesg, sk->faddr, areaid, ifa->oa->areaid);
+#endif
+    return 1;
+  }
+  else
   {
-    /* We limit logging of unmatched packets as it may be perfectly OK */
-    if (unmatched_count < 8)
+    /* Some vlink? */
+    struct ospf_iface *iff = NULL;
+
+    WALK_LIST(iff, po->iface_list)
     {
-      struct iface *ifc = if_find_by_index(sk->lifindex);
-      log(L_WARN "OSPF: Received unmatched packet (src %I, iface %s, rtid %R, area %R)",
-         sk->faddr, ifc ? ifc->name : "?", ntohl(ps->routerid), ntohl(ps->areaid));
-      unmatched_count++;
+      if ((iff->type == OSPF_IT_VLINK) && 
+         (iff->voa == ifa->oa) &&
+#ifdef OSPFv3
+         (iff->instance_id == ps->instance_id) &&
+#endif
+         (iff->vid == rid))
+       {
+         /* Vlink should be UP */
+         if (iff->state != OSPF_IS_PTP)
+           return 1;
+         
+         ifa = iff;
+         goto found;
+       }
     }
 
+#ifdef OSPFv2
+    log(L_WARN "OSPF: Received packet for uknown vlink (ID %R, IP %I)", rid, sk->faddr);
+#endif
     return 1;
   }
 
-  struct proto_ospf *po = ifa->oa->po;
-  struct proto *p = &po->proto;
-
+ found:
   if (ifa->stub)           /* This shouldn't happen */
     return 1;
 
   if (ipa_equal(sk->laddr, AllDRouters) && (ifa->sk_dr == 0))
     return 1;
 
-  if (ntohl(ps->routerid) == po->router_id)
+  if (rid == po->router_id)
   {
     log(L_ERR "%s%I - received my own router ID!", mesg, sk->faddr);
     return 1;
   }
 
-  if (ntohl(ps->routerid) == 0)
+  if (rid == 0)
   {
     log(L_ERR "%s%I - router id = 0.0.0.0", mesg, sk->faddr);
     return 1;
@@ -406,7 +435,7 @@ ospf_rx_hook(sock *sk, int size)
   /* This is deviation from RFC 2328 - neighbours should be identified by
    * IP address on broadcast and NBMA networks.
    */
-  struct ospf_neighbor *n = find_neigh(ifa, ntohl(ps->routerid));
+  struct ospf_neighbor *n = find_neigh(ifa, rid);
 
   if(!n && (ps->type != HELLO_P))
   {
index 053aba3b14cca76eafe92fa90554c0833702b332..1c74a7035a56dd348a9d88612f6ec6a9bbd2e72c 100644 (file)
@@ -19,6 +19,6 @@ void ospf_send_to_agt(struct ospf_iface *ifa, u8 state);
 void ospf_send_to_bdr(struct ospf_iface *ifa);
 void ospf_send_to(struct ospf_iface *ifa, ip_addr ip);
 
-static inline void * ospf_tx_buffer() { return ospf_socket->tbuf; }
+static inline void * ospf_tx_buffer(struct ospf_iface *ifa) { return ifa->sk->tbuf; }
 
 #endif /* _BIRD_OSPF_PACKET_H_ */