]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
OSPF: Minor refactoring of packet sending code
authorOndrej Zajicek (work) <santiago@crfreenet.org>
Sun, 9 May 2021 12:51:39 +0000 (14:51 +0200)
committerOndrej Zajicek (work) <santiago@crfreenet.org>
Sun, 9 May 2021 12:51:39 +0000 (14:51 +0200)
Common behavior for LSupd and delayed LSack moved to ospf_send_to_iface()
and other minor changes.

proto/ospf/lsack.c
proto/ospf/lsupd.c
proto/ospf/ospf.h
proto/ospf/packet.c

index 5318e50cad6845f6f9c15222f6c064077f4f61ae..1654953f72931f57caf1af4e9dbb0eff6bd3b5c3 100644 (file)
@@ -111,20 +111,12 @@ ospf_send_lsack_(struct ospf_proto *p, struct ospf_neighbor *n, int queue)
   {
     OSPF_PACKET(ospf_dump_lsack, pkt, "LSACK packet sent to nbr %R on %s", n->rid, ifa->ifname);
     ospf_send_to(ifa, n->ip);
-    return;
   }
-
-  OSPF_PACKET(ospf_dump_lsack, pkt, "LSACK packet sent via %s", ifa->ifname);
-
-  if (ifa->type == OSPF_IT_BCAST)
+  else
   {
-    if ((ifa->state == OSPF_IS_DR) || (ifa->state == OSPF_IS_BACKUP))
-      ospf_send_to_all(ifa);
-    else
-      ospf_send_to_des(ifa);
+    OSPF_PACKET(ospf_dump_lsack, pkt, "LSACK packet sent via %s", ifa->ifname);
+    ospf_send_to_iface(ifa);
   }
-  else
-    ospf_send_to_agt(ifa, NEIGHBOR_EXCHANGE);
 }
 
 void
index fafe4872ef2f4c2a47e87589941301fa9a1f5d26..66017a2e28407b0d422dcc4652215aba502a182d 100644 (file)
@@ -398,15 +398,7 @@ ospf_flood_lsupd(struct ospf_proto *p, struct top_hash_entry **lsa_list, uint ls
     OSPF_PACKET(ospf_dump_lsupd, ospf_tx_buffer(ifa),
                "LSUPD packet flooded via %s", ifa->ifname);
 
-    if (ifa->type == OSPF_IT_BCAST)
-    {
-      if ((ifa->state == OSPF_IS_DR) || (ifa->state == OSPF_IS_BACKUP))
-       ospf_send_to_all(ifa);
-      else
-       ospf_send_to_des(ifa);
-    }
-    else
-      ospf_send_to_agt(ifa, NEIGHBOR_EXCHANGE);
+    ospf_send_to_iface(ifa);
   }
 
   return i;
index db55aa6a1d8cebc0b4f638b761f6c0247d089813..aa7d937e9b9a113b7d0289e2cd11a43eb33780df 100644 (file)
@@ -1056,22 +1056,13 @@ int ospf_rx_hook(sock * sk, uint size);
 void ospf_err_hook(sock * sk, int err);
 void ospf_verr_hook(sock *sk, int err);
 void ospf_send_to(struct ospf_iface *ifa, ip_addr ip);
-void ospf_send_to_agt(struct ospf_iface *ifa, u8 state);
-void ospf_send_to_bdr(struct ospf_iface *ifa);
-
-static inline uint ospf_pkt_maxsize(struct ospf_iface *ifa)
-{ return ifa->tx_length - ifa->tx_hdrlen; }
+void ospf_send_to_iface(struct ospf_iface *ifa);
 
 static inline void ospf_send_to_all(struct ospf_iface *ifa)
 { ospf_send_to(ifa, ifa->all_routers); }
 
-static inline void ospf_send_to_des(struct ospf_iface *ifa)
-{
-  if (ipa_nonzero(ifa->des_routers))
-    ospf_send_to(ifa, ifa->des_routers);
-  else
-    ospf_send_to_bdr(ifa);
-}
+static inline uint ospf_pkt_maxsize(struct ospf_iface *ifa)
+{ return ifa->tx_length - ifa->tx_hdrlen; }
 
 #ifndef PARSER
 #define DROP(DSC,VAL) do { err_dsc = DSC; err_val = VAL; goto drop; } while(0)
index 85cbbdf06b1ba3eb13d282410c46594ee93a9d22..1f471d7933a68c4f849b2a5b8099286d6266aca7 100644 (file)
@@ -664,21 +664,44 @@ ospf_send_to(struct ospf_iface *ifa, ip_addr dst)
     log(L_WARN "OSPF: TX queue full on %s", ifa->ifname);
 }
 
-void
-ospf_send_to_agt(struct ospf_iface *ifa, u8 state)
+static void
+ospf_send_to_designated(struct ospf_iface *ifa)
+{
+  /* In case of real-broadcast mode */
+  if (ipa_zero(ifa->des_routers))
+  {
+    if (ipa_nonzero2(ifa->drip))
+      ospf_send_to(ifa, ifa->drip);
+
+    if (ipa_nonzero2(ifa->bdrip))
+      ospf_send_to(ifa, ifa->bdrip);
+
+    return;
+  }
+
+  ospf_send_to(ifa, ifa->des_routers);
+}
+
+static void
+ospf_send_to_adjacent(struct ospf_iface *ifa)
 {
   struct ospf_neighbor *n;
 
   WALK_LIST(n, ifa->neigh_list)
-    if (n->state >= state)
+    if (n->state >= NEIGHBOR_EXCHANGE)
       ospf_send_to(ifa, n->ip);
 }
 
 void
-ospf_send_to_bdr(struct ospf_iface *ifa)
+ospf_send_to_iface(struct ospf_iface *ifa)
 {
-  if (ipa_nonzero2(ifa->drip))
-    ospf_send_to(ifa, ifa->drip);
-  if (ipa_nonzero2(ifa->bdrip))
-    ospf_send_to(ifa, ifa->bdrip);
+  if (ifa->type == OSPF_IT_BCAST)
+  {
+    if ((ifa->state == OSPF_IS_DR) || (ifa->state == OSPF_IS_BACKUP))
+      ospf_send_to_all(ifa);
+    else
+      ospf_send_to_designated(ifa);
+  }
+  else /* Non-broadcast */
+    ospf_send_to_adjacent(ifa);
 }