OSPF: Minor refactoring of packet sending code

Common behavior for LSupd and delayed LSack moved to ospf_send_to_iface()
and other minor changes.
This commit is contained in:
Ondrej Zajicek (work) 2021-05-09 14:51:39 +02:00
parent 255722e0fc
commit 1647923bd8
4 changed files with 39 additions and 41 deletions

View 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_PACKET(ospf_dump_lsack, pkt, "LSACK packet sent to nbr %R on %s", n->rid, ifa->ifname);
ospf_send_to(ifa, n->ip); 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)
{
if ((ifa->state == OSPF_IS_DR) || (ifa->state == OSPF_IS_BACKUP))
ospf_send_to_all(ifa);
else
ospf_send_to_des(ifa);
} }
else else
ospf_send_to_agt(ifa, NEIGHBOR_EXCHANGE); {
OSPF_PACKET(ospf_dump_lsack, pkt, "LSACK packet sent via %s", ifa->ifname);
ospf_send_to_iface(ifa);
}
} }
void void

View 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), OSPF_PACKET(ospf_dump_lsupd, ospf_tx_buffer(ifa),
"LSUPD packet flooded via %s", ifa->ifname); "LSUPD packet flooded via %s", ifa->ifname);
if (ifa->type == OSPF_IT_BCAST) ospf_send_to_iface(ifa);
{
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);
} }
return i; return i;

View file

@ -1056,22 +1056,13 @@ int ospf_rx_hook(sock * sk, uint size);
void ospf_err_hook(sock * sk, int err); void ospf_err_hook(sock * sk, int err);
void ospf_verr_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(struct ospf_iface *ifa, ip_addr ip);
void ospf_send_to_agt(struct ospf_iface *ifa, u8 state); void ospf_send_to_iface(struct ospf_iface *ifa);
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; }
static inline void ospf_send_to_all(struct ospf_iface *ifa) static inline void ospf_send_to_all(struct ospf_iface *ifa)
{ ospf_send_to(ifa, ifa->all_routers); } { ospf_send_to(ifa, ifa->all_routers); }
static inline void ospf_send_to_des(struct ospf_iface *ifa) static inline uint ospf_pkt_maxsize(struct ospf_iface *ifa)
{ { return ifa->tx_length - ifa->tx_hdrlen; }
if (ipa_nonzero(ifa->des_routers))
ospf_send_to(ifa, ifa->des_routers);
else
ospf_send_to_bdr(ifa);
}
#ifndef PARSER #ifndef PARSER
#define DROP(DSC,VAL) do { err_dsc = DSC; err_val = VAL; goto drop; } while(0) #define DROP(DSC,VAL) do { err_dsc = DSC; err_val = VAL; goto drop; } while(0)

View 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); log(L_WARN "OSPF: TX queue full on %s", ifa->ifname);
} }
void static void
ospf_send_to_agt(struct ospf_iface *ifa, u8 state) 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; struct ospf_neighbor *n;
WALK_LIST(n, ifa->neigh_list) WALK_LIST(n, ifa->neigh_list)
if (n->state >= state) if (n->state >= NEIGHBOR_EXCHANGE)
ospf_send_to(ifa, n->ip); ospf_send_to(ifa, n->ip);
} }
void void
ospf_send_to_bdr(struct ospf_iface *ifa) ospf_send_to_iface(struct ospf_iface *ifa)
{ {
if (ipa_nonzero2(ifa->drip)) if (ifa->type == OSPF_IT_BCAST)
ospf_send_to(ifa, ifa->drip); {
if (ipa_nonzero2(ifa->bdrip)) if ((ifa->state == OSPF_IS_DR) || (ifa->state == OSPF_IS_BACKUP))
ospf_send_to(ifa, ifa->bdrip); ospf_send_to_all(ifa);
else
ospf_send_to_designated(ifa);
}
else /* Non-broadcast */
ospf_send_to_adjacent(ifa);
} }