Temporary OSPF commit - socket changes.
This commit is contained in:
parent
75f8861898
commit
353729f513
18 changed files with 615 additions and 295 deletions
|
@ -34,8 +34,11 @@ typedef struct birdsock {
|
||||||
|
|
||||||
void (*err_hook)(struct birdsock *, int); /* errno or zero if EOF */
|
void (*err_hook)(struct birdsock *, int); /* errno or zero if EOF */
|
||||||
|
|
||||||
ip_addr faddr; /* For packet protocols: source of current packet */
|
/* Information about received datagrams (UDP, RAW), valid in rx_hook */
|
||||||
unsigned fport;
|
ip_addr faddr, laddr; /* src (From) and dst (Local) address of the datagram */
|
||||||
|
unsigned fport; /* src port of the datagram */
|
||||||
|
unsigned lifindex; /* local interface that received the datagram */
|
||||||
|
/* laddr and lifindex are valid only if SKF_LADDR_RX flag is set to request it */
|
||||||
|
|
||||||
int fd; /* System-dependent data */
|
int fd; /* System-dependent data */
|
||||||
node n;
|
node n;
|
||||||
|
@ -74,6 +77,8 @@ sk_send_buffer_empty(sock *sk)
|
||||||
/* Socket flags */
|
/* Socket flags */
|
||||||
|
|
||||||
#define SKF_V6ONLY 1 /* Use IPV6_V6ONLY socket option */
|
#define SKF_V6ONLY 1 /* Use IPV6_V6ONLY socket option */
|
||||||
|
#define SKF_LADDR_RX 2 /* Report local address for RX packets */
|
||||||
|
#define SKF_LADDR_TX 4 /* Allow to specify local address for TX packets */
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -472,7 +472,7 @@ CF_CLI(RELOAD OUT, proto_patt, <protocol> | \"<pattern>\" | all, [[Reload protoc
|
||||||
{ proto_xxable($3, XX_RELOAD_OUT); } ;
|
{ proto_xxable($3, XX_RELOAD_OUT); } ;
|
||||||
|
|
||||||
CF_CLI_HELP(DEBUG, ..., [[Control protocol debugging via BIRD logs]])
|
CF_CLI_HELP(DEBUG, ..., [[Control protocol debugging via BIRD logs]])
|
||||||
CF_CLI(DEBUG, proto_patt debug_mask, (<protocol> | <pattern> | all) (all | off | { states | routes | filters | events | packets }), [[Control protocol debugging via BIRD logs]])
|
CF_CLI(DEBUG, proto_patt debug_mask, (<protocol> | <pattern> | all) (all | off | { states | routes | filters | interfaces | events | packets }), [[Control protocol debugging via BIRD logs]])
|
||||||
{ proto_debug($2, 0, $3); }
|
{ proto_debug($2, 0, $3); }
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
|
@ -93,8 +93,8 @@ ospf_dbdes_send(struct ospf_neighbor *n, int next)
|
||||||
{
|
{
|
||||||
case NEIGHBOR_EXSTART: /* Send empty packets */
|
case NEIGHBOR_EXSTART: /* Send empty packets */
|
||||||
n->myimms.bit.i = 1;
|
n->myimms.bit.i = 1;
|
||||||
pkt = (struct ospf_dbdes_packet *) (ifa->sk->tbuf);
|
pkt = ospf_tx_buffer();
|
||||||
op = (struct ospf_packet *) pkt;
|
op = &pkt->ospf_packet;
|
||||||
ospf_pkt_fill_hdr(ifa, pkt, DBDES_P);
|
ospf_pkt_fill_hdr(ifa, pkt, DBDES_P);
|
||||||
pkt->iface_mtu = htons(ifa->iface->mtu);
|
pkt->iface_mtu = htons(ifa->iface->mtu);
|
||||||
pkt->options = hton_opt(oa->options);
|
pkt->options = hton_opt(oa->options);
|
||||||
|
@ -185,10 +185,10 @@ ospf_dbdes_send(struct ospf_neighbor *n, int next)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy last sent packet again */
|
/* Copy last sent packet again */
|
||||||
memcpy(ifa->sk->tbuf, n->ldbdes, length);
|
pkt = ospf_tx_buffer();
|
||||||
|
memcpy(pkt, n->ldbdes, length);
|
||||||
|
|
||||||
OSPF_PACKET(ospf_dump_dbdes, (struct ospf_dbdes_packet *) ifa->sk->tbuf,
|
OSPF_PACKET(ospf_dump_dbdes, pkt, "DBDES packet sent to %I via %s", n->ip, ifa->iface->name);
|
||||||
"DBDES packet sent to %I via %s", n->ip, ifa->iface->name);
|
|
||||||
ospf_send_to(ifa, n->ip);
|
ospf_send_to(ifa, n->ip);
|
||||||
|
|
||||||
if(n->myimms.bit.ms) tm_start(n->rxmt_timer, n->ifa->rxmtint); /* Restart timer */
|
if(n->myimms.bit.ms) tm_start(n->rxmt_timer, n->ifa->rxmtint); /* Restart timer */
|
||||||
|
|
|
@ -47,7 +47,7 @@ ospf_hello_receive(struct ospf_packet *ps_i, struct ospf_iface *ifa,
|
||||||
{
|
{
|
||||||
struct proto_ospf *po = ifa->oa->po;
|
struct proto_ospf *po = ifa->oa->po;
|
||||||
struct proto *p = &po->proto;
|
struct proto *p = &po->proto;
|
||||||
char *beg = "Bad OSPF HELLO packet from ", *rec = " received: ";
|
char *beg = "OSPF: Bad HELLO packet from ";
|
||||||
unsigned int size, i, twoway, oldpriority, eligible, peers;
|
unsigned int size, i, twoway, oldpriority, eligible, peers;
|
||||||
u32 olddr, oldbdr, oldiface_id, tmp;
|
u32 olddr, oldbdr, oldiface_id, tmp;
|
||||||
u32 *pnrid;
|
u32 *pnrid;
|
||||||
|
@ -67,38 +67,19 @@ ospf_hello_receive(struct ospf_packet *ps_i, struct ospf_iface *ifa,
|
||||||
#ifdef OSPFv2
|
#ifdef OSPFv2
|
||||||
ip_addr mask = ps->netmask;
|
ip_addr mask = ps->netmask;
|
||||||
ipa_ntoh(mask);
|
ipa_ntoh(mask);
|
||||||
if (ifa->type != OSPF_IT_VLINK)
|
if ((ifa->type != OSPF_IT_VLINK) &&
|
||||||
|
(ifa->type != OSPF_IT_PTP) &&
|
||||||
|
!ipa_equal(mask, ipa_mkmask(ifa->addr->pxlen)))
|
||||||
{
|
{
|
||||||
char *msg = L_WARN "Received HELLO packet %s (%I) is inconsistent "
|
log(L_ERR "%s%I - netmask mismatch (%I)", beg, faddr, mask);
|
||||||
"with the primary address of interface %s.";
|
|
||||||
|
|
||||||
if ((ifa->type != OSPF_IT_PTP) &&
|
|
||||||
!ipa_equal(mask, ipa_mkmask(ifa->iface->addr->pxlen)))
|
|
||||||
{
|
|
||||||
if (!n) log(msg, "netmask", mask, ifa->iface->name);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This check is not specified in RFC 2328, but it is needed
|
|
||||||
* to handle the case when there is more IP networks on one
|
|
||||||
* physical network (which is not handled in RFC 2328).
|
|
||||||
* We allow OSPF on primary IP address only and ignore HELLO packets
|
|
||||||
* with secondary addresses (which are sent for example by Quagga.
|
|
||||||
*/
|
|
||||||
if ((ifa->iface->addr->flags & IA_UNNUMBERED) ?
|
|
||||||
!ipa_equal(faddr, ifa->iface->addr->opposite) :
|
|
||||||
!ipa_equal(ipa_and(faddr,mask), ifa->iface->addr->prefix))
|
|
||||||
{
|
|
||||||
if (!n) log(msg, "address", faddr, ifa->iface->name);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
tmp = ntohs(ps->helloint);
|
tmp = ntohs(ps->helloint);
|
||||||
if (tmp != ifa->helloint)
|
if (tmp != ifa->helloint)
|
||||||
{
|
{
|
||||||
log(L_ERR "%s%I%shello interval mismatch (%d).", beg, faddr, rec, tmp);
|
log(L_ERR "%s%I - hello interval mismatch (%d)", beg, faddr, tmp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -109,14 +90,14 @@ ospf_hello_receive(struct ospf_packet *ps_i, struct ospf_iface *ifa,
|
||||||
#endif
|
#endif
|
||||||
if (tmp != ifa->dead)
|
if (tmp != ifa->dead)
|
||||||
{
|
{
|
||||||
log(L_ERR "%s%I%sdead interval mismatch (%d).", beg, faddr, rec, tmp);
|
log(L_ERR "%s%I - dead interval mismatch (%d)", beg, faddr, tmp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp = !(ps->options & OPT_E);
|
tmp = !(ps->options & OPT_E);
|
||||||
if (tmp != ifa->oa->stub)
|
if (tmp != ifa->oa->stub)
|
||||||
{
|
{
|
||||||
log(L_ERR "%s%I%sstub area flag mismatch (%d).", beg, faddr, rec, tmp);
|
log(L_ERR "%s%I - stub area flag mismatch (%d)", beg, faddr, tmp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +118,7 @@ ospf_hello_receive(struct ospf_packet *ps_i, struct ospf_iface *ifa,
|
||||||
}
|
}
|
||||||
if ((found == 0) && (ifa->strictnbma))
|
if ((found == 0) && (ifa->strictnbma))
|
||||||
{
|
{
|
||||||
log(L_WARN "Ignoring new neighbor: %I on %s.", faddr,
|
log(L_WARN "Ignoring new neighbor: %I on %s", faddr,
|
||||||
ifa->iface->name);
|
ifa->iface->name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -153,7 +134,7 @@ ospf_hello_receive(struct ospf_packet *ps_i, struct ospf_iface *ifa,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
OSPF_TRACE(D_EVENTS, "New neighbor found: %I on %s.", faddr,
|
OSPF_TRACE(D_EVENTS, "New neighbor found: %I on %s", faddr,
|
||||||
ifa->iface->name);
|
ifa->iface->name);
|
||||||
|
|
||||||
n = ospf_neighbor_new(ifa);
|
n = ospf_neighbor_new(ifa);
|
||||||
|
@ -277,14 +258,14 @@ ospf_hello_send(timer *timer, int poll, struct ospf_neighbor *dirn)
|
||||||
p->name, ifa->iface->name);
|
p->name, ifa->iface->name);
|
||||||
|
|
||||||
/* Now we should send a hello packet */
|
/* Now we should send a hello packet */
|
||||||
pkt = (struct ospf_hello_packet *) (ifa->sk->tbuf);
|
pkt = ospf_tx_buffer();
|
||||||
op = (struct ospf_packet *) pkt;
|
op = &pkt->ospf_packet;
|
||||||
|
|
||||||
/* Now fill ospf_hello header */
|
/* Now fill ospf_hello header */
|
||||||
ospf_pkt_fill_hdr(ifa, pkt, HELLO_P);
|
ospf_pkt_fill_hdr(ifa, pkt, HELLO_P);
|
||||||
|
|
||||||
#ifdef OSPFv2
|
#ifdef OSPFv2
|
||||||
pkt->netmask = ipa_mkmask(ifa->iface->addr->pxlen);
|
pkt->netmask = ipa_mkmask(ifa->addr->pxlen);
|
||||||
ipa_hton(pkt->netmask);
|
ipa_hton(pkt->netmask);
|
||||||
if ((ifa->type == OSPF_IT_VLINK) || (ifa->type == OSPF_IT_PTP))
|
if ((ifa->type == OSPF_IT_VLINK) || (ifa->type == OSPF_IT_PTP))
|
||||||
pkt->netmask = IPA_NONE;
|
pkt->netmask = IPA_NONE;
|
||||||
|
|
|
@ -58,15 +58,15 @@ rxbufsize(struct ospf_iface *ifa)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static sock *
|
static int
|
||||||
ospf_open_socket(struct ospf_iface *ifa, int mc)
|
ospf_sk_open(struct ospf_iface *ifa, int mc)
|
||||||
{
|
{
|
||||||
sock *ipsk;
|
sock *sk;
|
||||||
struct proto *p = &ifa->oa->po->proto;
|
struct proto *p = &ifa->oa->po->proto;
|
||||||
|
|
||||||
ipsk = sk_new(p->pool);
|
sk = sk_new(p->pool);
|
||||||
ipsk->type = SK_IP;
|
sk->type = SK_IP;
|
||||||
ipsk->dport = OSPF_PROTO;
|
sk->dport = OSPF_PROTO;
|
||||||
|
|
||||||
#ifdef OSPFv2
|
#ifdef OSPFv2
|
||||||
/*
|
/*
|
||||||
|
@ -76,45 +76,93 @@ ospf_open_socket(struct ospf_iface *ifa, int mc)
|
||||||
*
|
*
|
||||||
* We want such filter in the vlink (non-mc) socket.
|
* We want such filter in the vlink (non-mc) socket.
|
||||||
*/
|
*/
|
||||||
ipsk->saddr = mc ? IPA_NONE : ifa->iface->addr->ip;
|
sk->saddr = mc ? IPA_NONE : ifa->addr->ip;
|
||||||
#else /* OSPFv3 */
|
#else /* OSPFv3 */
|
||||||
ipsk->saddr = ifa->lladdr;
|
sk->saddr = ifa->addr->ip; /* link-local addr */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ipsk->tos = IP_PREC_INTERNET_CONTROL;
|
sk->tos = IP_PREC_INTERNET_CONTROL;
|
||||||
ipsk->ttl = 1;
|
sk->ttl = 1;
|
||||||
if (ifa->type == OSPF_IT_VLINK)
|
if (ifa->type == OSPF_IT_VLINK)
|
||||||
ipsk->ttl = 255;
|
sk->ttl = 255;
|
||||||
ipsk->rx_hook = ospf_rx_hook;
|
sk->rx_hook = ospf_rx_hook;
|
||||||
ipsk->tx_hook = ospf_tx_hook;
|
sk->tx_hook = ospf_tx_hook;
|
||||||
ipsk->err_hook = ospf_err_hook;
|
sk->err_hook = ospf_err_hook;
|
||||||
ipsk->iface = ifa->iface;
|
sk->iface = ifa->iface;
|
||||||
ipsk->rbsize = rxbufsize(ifa);
|
sk->rbsize = rxbufsize(ifa);
|
||||||
ipsk->tbsize = ifa->iface->mtu;
|
sk->tbsize = ifa->iface->mtu;
|
||||||
ipsk->data = (void *) ifa;
|
sk->data = (void *) ifa;
|
||||||
if (sk_open(ipsk) != 0)
|
sk->flags = SKF_LADDR_RX;
|
||||||
|
|
||||||
|
if (sk_open(sk) != 0)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
#ifdef OSPFv3
|
#ifdef OSPFv3
|
||||||
/* 12 is an offset of the checksum in an OSPF packet */
|
/* 12 is an offset of the checksum in an OSPF packet */
|
||||||
if (sk_set_ipv6_checksum(ipsk, 12) < 0)
|
if (sk_set_ipv6_checksum(sk, 12) < 0)
|
||||||
goto err;
|
goto err;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (mc)
|
if (mc && (sk_setup_multicast(sk) < 0))
|
||||||
{
|
|
||||||
if (sk_setup_multicast(ipsk) < 0)
|
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
if (sk_join_group(ipsk, AllSPFRouters) < 0)
|
ifa->sk = sk;
|
||||||
goto err;
|
ifa->sk_spf = 0;
|
||||||
}
|
ifa->sk_dr = 0;
|
||||||
|
return 1;
|
||||||
return ipsk;
|
|
||||||
|
|
||||||
err:
|
err:
|
||||||
rfree(ipsk);
|
rfree(sk);
|
||||||
return NULL;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
ospf_sk_join_spf(struct ospf_iface *ifa)
|
||||||
|
{
|
||||||
|
if (ifa->sk_spf)
|
||||||
|
return;
|
||||||
|
|
||||||
|
sk_join_group(ifa->sk, AllSPFRouters);
|
||||||
|
ifa->sk_spf = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
ospf_sk_join_dr(struct ospf_iface *ifa)
|
||||||
|
{
|
||||||
|
if (ifa->sk_dr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
sk_join_group(ifa->sk, AllDRouters);
|
||||||
|
ifa->sk_dr = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
ospf_sk_leave_spf(struct ospf_iface *ifa)
|
||||||
|
{
|
||||||
|
if (!ifa->sk_spf)
|
||||||
|
return;
|
||||||
|
|
||||||
|
sk_leave_group(ifa->sk, AllSPFRouters);
|
||||||
|
ifa->sk_spf = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
ospf_sk_leave_dr(struct ospf_iface *ifa)
|
||||||
|
{
|
||||||
|
if (!ifa->sk_dr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
sk_leave_group(ifa->sk, AllDRouters);
|
||||||
|
ifa->sk_dr = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
ospf_sk_close(struct ospf_iface *ifa)
|
||||||
|
{
|
||||||
|
ASSERT(ifa->sk);
|
||||||
|
|
||||||
|
rfree(ifa->sk);
|
||||||
|
ifa->sk = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -144,9 +192,9 @@ ospf_iface_chstate(struct ospf_iface *ifa, u8 state)
|
||||||
"Changing state of virtual link %R from \"%s\" into \"%s\".",
|
"Changing state of virtual link %R from \"%s\" into \"%s\".",
|
||||||
ifa->vid, ospf_is[oldstate], ospf_is[state]);
|
ifa->vid, ospf_is[oldstate], ospf_is[state]);
|
||||||
if (state == OSPF_IS_PTP)
|
if (state == OSPF_IS_PTP)
|
||||||
{
|
ospf_sk_open(ifa, 0);
|
||||||
ifa->sk = ospf_open_socket(ifa, 0);
|
if (state == OSPF_IS_DOWN)
|
||||||
}
|
ospf_sk_close(ifa);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -157,19 +205,10 @@ ospf_iface_chstate(struct ospf_iface *ifa, u8 state)
|
||||||
{
|
{
|
||||||
if ((ifa->type != OSPF_IT_NBMA) && (ifa->ioprob == OSPF_I_OK) &&
|
if ((ifa->type != OSPF_IT_NBMA) && (ifa->ioprob == OSPF_I_OK) &&
|
||||||
((state == OSPF_IS_BACKUP) || (state == OSPF_IS_DR)))
|
((state == OSPF_IS_BACKUP) || (state == OSPF_IS_DR)))
|
||||||
{
|
ospf_sk_join_dr(ifa);
|
||||||
if (!ifa->dr_up == 0)
|
else
|
||||||
{
|
ospf_sk_leave_dr(ifa);
|
||||||
/* FIXME some error handing ? */
|
|
||||||
sk_join_group(ifa->sk, AllDRouters);
|
|
||||||
ifa->dr_up = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (ifa->dr_up)
|
|
||||||
{
|
|
||||||
sk_leave_group(ifa->sk, AllDRouters);
|
|
||||||
ifa->dr_up = 0;
|
|
||||||
}
|
|
||||||
if ((oldstate == OSPF_IS_DR) && (ifa->net_lsa != NULL))
|
if ((oldstate == OSPF_IS_DR) && (ifa->net_lsa != NULL))
|
||||||
{
|
{
|
||||||
ifa->net_lsa->lsa.age = LSA_MAXAGE;
|
ifa->net_lsa->lsa.age = LSA_MAXAGE;
|
||||||
|
@ -182,6 +221,7 @@ ospf_iface_chstate(struct ospf_iface *ifa, u8 state)
|
||||||
ifa->net_lsa = NULL;
|
ifa->net_lsa = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// FIXME flushling of link LSA
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -194,13 +234,15 @@ ospf_iface_down(struct ospf_iface *ifa)
|
||||||
struct proto *p = &po->proto;
|
struct proto *p = &po->proto;
|
||||||
struct ospf_iface *iff;
|
struct ospf_iface *iff;
|
||||||
|
|
||||||
|
OSPF_TRACE(D_EVENTS, "Removing interface %s", ifa->iface->name);
|
||||||
|
|
||||||
/* First of all kill all the related vlinks */
|
/* First of all kill all the related vlinks */
|
||||||
if (ifa->type != OSPF_IT_VLINK)
|
if (ifa->type != OSPF_IT_VLINK)
|
||||||
{
|
{
|
||||||
WALK_LIST(iff, po->iface_list)
|
WALK_LIST(iff, po->iface_list)
|
||||||
{
|
{
|
||||||
if ((iff->type == OSPF_IT_VLINK) && (iff->iface == ifa->iface))
|
if ((iff->type == OSPF_IT_VLINK) && (iff->iface == ifa->iface))
|
||||||
ospf_iface_down(iff);
|
ospf_iface_sm(iff, ISM_DOWN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,9 +252,6 @@ ospf_iface_down(struct ospf_iface *ifa)
|
||||||
ospf_neigh_remove(n);
|
ospf_neigh_remove(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
rfree(ifa->sk);
|
|
||||||
ifa->sk = NULL;
|
|
||||||
|
|
||||||
if (ifa->type == OSPF_IT_VLINK)
|
if (ifa->type == OSPF_IT_VLINK)
|
||||||
{
|
{
|
||||||
ifa->iface = NULL;
|
ifa->iface = NULL;
|
||||||
|
@ -220,6 +259,7 @@ ospf_iface_down(struct ospf_iface *ifa)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
ospf_sk_close(ifa);
|
||||||
rfree(ifa->wait_timer);
|
rfree(ifa->wait_timer);
|
||||||
rfree(ifa->hello_timer);
|
rfree(ifa->hello_timer);
|
||||||
rfree(ifa->poll_timer);
|
rfree(ifa->poll_timer);
|
||||||
|
@ -294,18 +334,16 @@ ospf_iface_sm(struct ospf_iface *ifa, int event)
|
||||||
case ISM_DOWN:
|
case ISM_DOWN:
|
||||||
ospf_iface_chstate(ifa, OSPF_IS_DOWN);
|
ospf_iface_chstate(ifa, OSPF_IS_DOWN);
|
||||||
ospf_iface_down(ifa);
|
ospf_iface_down(ifa);
|
||||||
schedule_link_lsa(ifa);
|
|
||||||
schedule_rt_lsa(oa);
|
schedule_rt_lsa(oa);
|
||||||
break;
|
break;
|
||||||
case ISM_LOOP: /* Useless? */
|
/*
|
||||||
|
case ISM_LOOP:
|
||||||
ospf_iface_chstate(ifa, OSPF_IS_LOOP);
|
ospf_iface_chstate(ifa, OSPF_IS_LOOP);
|
||||||
ospf_iface_down(ifa);
|
|
||||||
schedule_rt_lsa(ifa->oa);
|
|
||||||
break;
|
break;
|
||||||
case ISM_UNLOOP:
|
case ISM_UNLOOP:
|
||||||
ospf_iface_chstate(ifa, OSPF_IS_DOWN);
|
ospf_iface_chstate(ifa, OSPF_IS_DOWN);
|
||||||
schedule_rt_lsa(ifa->oa);
|
|
||||||
break;
|
break;
|
||||||
|
*/
|
||||||
default:
|
default:
|
||||||
bug("OSPF_I_SM - Unknown event?");
|
bug("OSPF_I_SM - Unknown event?");
|
||||||
break;
|
break;
|
||||||
|
@ -313,45 +351,6 @@ ospf_iface_sm(struct ospf_iface *ifa, int event)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
static sock *
|
|
||||||
ospf_open_mc_socket(struct ospf_iface *ifa)
|
|
||||||
{
|
|
||||||
sock *mcsk;
|
|
||||||
struct proto *p = &ifa->oa->po->proto;
|
|
||||||
|
|
||||||
mcsk = sk_new(p->pool);
|
|
||||||
mcsk->type = SK_IP_MC;
|
|
||||||
mcsk->sport = 0;
|
|
||||||
mcsk->dport = OSPF_PROTO;
|
|
||||||
|
|
||||||
#ifdef OSPFv2
|
|
||||||
mcsk->saddr = AllSPFRouters;
|
|
||||||
#else /* OSPFv3 */
|
|
||||||
// mcsk->saddr = AllSPFRouters;
|
|
||||||
mcsk->saddr = ifa->lladdr;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
mcsk->daddr = AllSPFRouters;
|
|
||||||
mcsk->tos = IP_PREC_INTERNET_CONTROL;
|
|
||||||
mcsk->ttl = 1;
|
|
||||||
mcsk->rx_hook = ospf_rx_hook;
|
|
||||||
mcsk->tx_hook = ospf_tx_hook;
|
|
||||||
mcsk->err_hook = ospf_err_hook;
|
|
||||||
mcsk->iface = ifa->iface;
|
|
||||||
mcsk->rbsize = rxbufsize(ifa);
|
|
||||||
mcsk->tbsize = ifa->iface->mtu;
|
|
||||||
mcsk->data = (void *) ifa;
|
|
||||||
if (sk_open(mcsk) != 0)
|
|
||||||
{
|
|
||||||
DBG("%s: SK_OPEN: mc open failed.\n", p->name);
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
DBG("%s: SK_OPEN: mc opened.\n", p->name);
|
|
||||||
return (mcsk);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
u8
|
u8
|
||||||
ospf_iface_clasify(struct iface * ifa)
|
ospf_iface_clasify(struct iface * ifa)
|
||||||
{
|
{
|
||||||
|
@ -390,12 +389,15 @@ ospf_iface_add(struct object_lock *lock)
|
||||||
|
|
||||||
ifa->ioprob = OSPF_I_OK;
|
ifa->ioprob = OSPF_I_OK;
|
||||||
|
|
||||||
ifa->sk = ospf_open_socket(ifa, ifa->type != OSPF_IT_NBMA);
|
ospf_sk_open(ifa, 1);
|
||||||
if (ifa->sk == NULL)
|
if (ifa->type != OSPF_IT_NBMA)
|
||||||
|
ospf_sk_join_spf(ifa);
|
||||||
|
|
||||||
|
if (0)
|
||||||
{
|
{
|
||||||
log("%s: Huh? could not open ip socket on interface %s?", p->name,
|
log(L_ERR "%s: Huh? could not open ip socket on interface %s?", p->name,
|
||||||
iface->name);
|
iface->name);
|
||||||
log("%s: Declaring as stub.", p->name);
|
log(L_ERR "%s: Declaring as stub.", p->name);
|
||||||
ifa->stub = 1;
|
ifa->stub = 1;
|
||||||
ifa->ioprob += OSPF_I_IP;
|
ifa->ioprob += OSPF_I_IP;
|
||||||
}
|
}
|
||||||
|
@ -414,6 +416,9 @@ ospf_iface_new(struct proto_ospf *po, struct iface *iface,
|
||||||
struct object_lock *lock;
|
struct object_lock *lock;
|
||||||
struct ospf_area *oa;
|
struct ospf_area *oa;
|
||||||
|
|
||||||
|
if (ip->type != OSPF_IT_VLINK)
|
||||||
|
OSPF_TRACE(D_EVENTS, "Adding interface %s", iface->name);
|
||||||
|
|
||||||
ifa = mb_allocz(p->pool, sizeof(struct ospf_iface));
|
ifa = mb_allocz(p->pool, sizeof(struct ospf_iface));
|
||||||
ifa->iface = iface;
|
ifa->iface = iface;
|
||||||
|
|
||||||
|
@ -431,12 +436,13 @@ ospf_iface_new(struct proto_ospf *po, struct iface *iface,
|
||||||
#ifdef OSPFv2
|
#ifdef OSPFv2
|
||||||
ifa->autype = ip->autype;
|
ifa->autype = ip->autype;
|
||||||
ifa->passwords = ip->passwords;
|
ifa->passwords = ip->passwords;
|
||||||
|
ifa->addr = iface->addr;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef OSPFv3
|
#ifdef OSPFv3
|
||||||
ifa->instance_id = ip->instance_id;
|
ifa->instance_id = ip->instance_id;
|
||||||
|
|
||||||
ifa->lladdr = IPA_NONE;
|
ifa->addr = NULL;
|
||||||
|
|
||||||
/* Find link-local address */
|
/* Find link-local address */
|
||||||
if (ifa->type != OSPF_IT_VLINK)
|
if (ifa->type != OSPF_IT_VLINK)
|
||||||
|
@ -445,11 +451,11 @@ ospf_iface_new(struct proto_ospf *po, struct iface *iface,
|
||||||
WALK_LIST(a, iface->addrs)
|
WALK_LIST(a, iface->addrs)
|
||||||
if (a->scope == SCOPE_LINK)
|
if (a->scope == SCOPE_LINK)
|
||||||
{
|
{
|
||||||
ifa->lladdr = a->ip;
|
ifa->addr = a;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! ipa_nonzero(ifa->lladdr))
|
if (! ifa->addr)
|
||||||
log(L_WARN "%s: Missing link local address on interface %s", p->name, iface->name);
|
log(L_WARN "%s: Missing link local address on interface %s", p->name, iface->name);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -594,20 +600,14 @@ ospf_iface_notify(struct proto *p, unsigned flags, struct iface *iface)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ip)
|
if (ip)
|
||||||
{
|
|
||||||
OSPF_TRACE(D_EVENTS, "Using interface %s.", iface->name);
|
|
||||||
ospf_iface_new(po, iface, ac, ip);
|
ospf_iface_new(po, iface, ac, ip);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (flags & IF_CHANGE_DOWN)
|
if (flags & IF_CHANGE_DOWN)
|
||||||
{
|
{
|
||||||
if ((ifa = ospf_iface_find((struct proto_ospf *) p, iface)) != NULL)
|
if ((ifa = ospf_iface_find((struct proto_ospf *) p, iface)) != NULL)
|
||||||
{
|
|
||||||
OSPF_TRACE(D_EVENTS, "Killing interface %s.", iface->name);
|
|
||||||
ospf_iface_sm(ifa, ISM_DOWN);
|
ospf_iface_sm(ifa, ISM_DOWN);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (flags & IF_CHANGE_MTU)
|
if (flags & IF_CHANGE_MTU)
|
||||||
{
|
{
|
||||||
|
@ -666,4 +666,5 @@ ospf_iface_shutdown(struct ospf_iface *ifa)
|
||||||
{
|
{
|
||||||
init_list(&ifa->neigh_list);
|
init_list(&ifa->neigh_list);
|
||||||
hello_timer_hook(ifa->hello_timer);
|
hello_timer_hook(ifa->hello_timer);
|
||||||
|
ospf_sk_close(ifa);
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,8 +66,8 @@ ospf_lsack_send(struct ospf_neighbor *n, int queue)
|
||||||
if (EMPTY_LIST(n->ackl[queue]))
|
if (EMPTY_LIST(n->ackl[queue]))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pk = (struct ospf_lsack_packet *) ifa->sk->tbuf;
|
pk = ospf_tx_buffer();
|
||||||
op = (struct ospf_packet *) ifa->sk->tbuf;
|
op = &pk->ospf_packet;
|
||||||
|
|
||||||
ospf_pkt_fill_hdr(n->ifa, pk, LSACK_P);
|
ospf_pkt_fill_hdr(n->ifa, pk, LSACK_P);
|
||||||
h = pk->lsh;
|
h = pk->lsh;
|
||||||
|
@ -92,8 +92,7 @@ ospf_lsack_send(struct ospf_neighbor *n, int queue)
|
||||||
op->length = htons(len);
|
op->length = htons(len);
|
||||||
DBG("Sending and continuing! Len=%u\n", len);
|
DBG("Sending and continuing! Len=%u\n", len);
|
||||||
|
|
||||||
OSPF_PACKET(ospf_dump_lsack, (struct ospf_lsack_packet *) ifa->sk->tbuf,
|
OSPF_PACKET(ospf_dump_lsack, pk, "LSACK packet sent via %s", ifa->iface->name);
|
||||||
"LSACK packet sent via %s", ifa->iface->name);
|
|
||||||
|
|
||||||
if (ifa->type == OSPF_IT_BCAST)
|
if (ifa->type == OSPF_IT_BCAST)
|
||||||
{
|
{
|
||||||
|
@ -120,8 +119,7 @@ ospf_lsack_send(struct ospf_neighbor *n, int queue)
|
||||||
op->length = htons(len);
|
op->length = htons(len);
|
||||||
DBG("Sending! Len=%u\n", len);
|
DBG("Sending! Len=%u\n", len);
|
||||||
|
|
||||||
OSPF_PACKET(ospf_dump_lsack, (struct ospf_lsack_packet *) ifa->sk->tbuf,
|
OSPF_PACKET(ospf_dump_lsack, pk, "LSACK packet sent via %s", ifa->iface->name);
|
||||||
"LSACK packet sent via %s", ifa->iface->name);
|
|
||||||
|
|
||||||
if (ifa->type == OSPF_IT_BCAST)
|
if (ifa->type == OSPF_IT_BCAST)
|
||||||
{
|
{
|
||||||
|
|
|
@ -44,8 +44,8 @@ ospf_lsreq_send(struct ospf_neighbor *n)
|
||||||
int i, j;
|
int i, j;
|
||||||
struct proto *p = &n->ifa->oa->po->proto;
|
struct proto *p = &n->ifa->oa->po->proto;
|
||||||
|
|
||||||
pk = (struct ospf_lsreq_packet *) n->ifa->sk->tbuf;
|
pk = ospf_tx_buffer();
|
||||||
op = (struct ospf_packet *) n->ifa->sk->tbuf;
|
op = &pk->ospf_packet;
|
||||||
|
|
||||||
ospf_pkt_fill_hdr(n->ifa, pk, LSREQ_P);
|
ospf_pkt_fill_hdr(n->ifa, pk, LSREQ_P);
|
||||||
|
|
||||||
|
@ -82,8 +82,7 @@ ospf_lsreq_send(struct ospf_neighbor *n)
|
||||||
i) * sizeof(struct ospf_lsreq_header);
|
i) * sizeof(struct ospf_lsreq_header);
|
||||||
op->length = htons(length);
|
op->length = htons(length);
|
||||||
|
|
||||||
OSPF_PACKET(ospf_dump_lsreq, (struct ospf_lsreq_packet *) n->ifa->sk->tbuf,
|
OSPF_PACKET(ospf_dump_lsreq, pk, "LSREQ packet sent to %I via %s", n->ip, n->ifa->iface->name);
|
||||||
"LSREQ packet sent to %I via %s", n->ip, n->ifa->iface->name);
|
|
||||||
ospf_send_to(n->ifa, n->ip);
|
ospf_send_to(n->ifa, n->ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -269,8 +269,8 @@ ospf_lsupd_flood(struct proto_ospf *po,
|
||||||
struct ospf_packet *op;
|
struct ospf_packet *op;
|
||||||
struct ospf_lsa_header *lh;
|
struct ospf_lsa_header *lh;
|
||||||
|
|
||||||
pk = (struct ospf_lsupd_packet *) ifa->sk->tbuf;
|
pk = ospf_tx_buffer();
|
||||||
op = (struct ospf_packet *) ifa->sk->tbuf;
|
op = &pk->ospf_packet;
|
||||||
|
|
||||||
ospf_pkt_fill_hdr(ifa, pk, LSUPD_P);
|
ospf_pkt_fill_hdr(ifa, pk, LSUPD_P);
|
||||||
pk->lsano = htonl(1);
|
pk->lsano = htonl(1);
|
||||||
|
@ -304,8 +304,7 @@ ospf_lsupd_flood(struct proto_ospf *po,
|
||||||
|
|
||||||
op->length = htons(len);
|
op->length = htons(len);
|
||||||
|
|
||||||
OSPF_PACKET(ospf_dump_lsupd, (struct ospf_lsupd_packet *) ifa->sk->tbuf,
|
OSPF_PACKET(ospf_dump_lsupd, pk, "LSUPD packet flooded via %s", ifa->iface->name);
|
||||||
"LSUPD packet flooded via %s", ifa->iface->name);
|
|
||||||
|
|
||||||
switch (ifa->type)
|
switch (ifa->type)
|
||||||
{
|
{
|
||||||
|
@ -349,11 +348,11 @@ ospf_lsupd_send_list(struct ospf_neighbor *n, list * l)
|
||||||
if (EMPTY_LIST(*l))
|
if (EMPTY_LIST(*l))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pk = (struct ospf_lsupd_packet *) n->ifa->sk->tbuf;
|
|
||||||
op = (struct ospf_packet *) n->ifa->sk->tbuf;
|
|
||||||
|
|
||||||
DBG("LSupd: 1st packet\n");
|
DBG("LSupd: 1st packet\n");
|
||||||
|
|
||||||
|
pk= ospf_tx_buffer();
|
||||||
|
op = &pk->ospf_packet;
|
||||||
|
|
||||||
ospf_pkt_fill_hdr(n->ifa, pk, LSUPD_P);
|
ospf_pkt_fill_hdr(n->ifa, pk, LSUPD_P);
|
||||||
len = sizeof(struct ospf_lsupd_packet);
|
len = sizeof(struct ospf_lsupd_packet);
|
||||||
lsano = 0;
|
lsano = 0;
|
||||||
|
@ -374,8 +373,7 @@ ospf_lsupd_send_list(struct ospf_neighbor *n, list * l)
|
||||||
pk->lsano = htonl(lsano);
|
pk->lsano = htonl(lsano);
|
||||||
op->length = htons(len);
|
op->length = htons(len);
|
||||||
|
|
||||||
OSPF_PACKET(ospf_dump_lsupd, (struct ospf_lsupd_packet *) n->ifa->sk->tbuf,
|
OSPF_PACKET(ospf_dump_lsupd, pk, "LSUPD packet sent to %I via %s", n->ip, n->ifa->iface->name);
|
||||||
"LSUPD packet sent to %I via %s", n->ip, n->ifa->iface->name);
|
|
||||||
ospf_send_to(n->ifa, n->ip);
|
ospf_send_to(n->ifa, n->ip);
|
||||||
|
|
||||||
DBG("LSupd: next packet\n");
|
DBG("LSupd: next packet\n");
|
||||||
|
@ -397,8 +395,7 @@ ospf_lsupd_send_list(struct ospf_neighbor *n, list * l)
|
||||||
pk->lsano = htonl(lsano);
|
pk->lsano = htonl(lsano);
|
||||||
op->length = htons(len);
|
op->length = htons(len);
|
||||||
|
|
||||||
OSPF_PACKET(ospf_dump_lsupd, (struct ospf_lsupd_packet *) n->ifa->sk->tbuf,
|
OSPF_PACKET(ospf_dump_lsupd, pk, "LSUPD packet sent to %I via %s", n->ip, n->ifa->iface->name);
|
||||||
"LSUPD packet sent to %I via %s", n->ip, n->ifa->iface->name);
|
|
||||||
ospf_send_to(n->ifa, n->ip);
|
ospf_send_to(n->ifa, n->ip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -416,7 +413,7 @@ ospf_lsupd_receive(struct ospf_packet *ps_i, struct ospf_iface *ifa,
|
||||||
unsigned int size = ntohs(ps_i->length);
|
unsigned int size = ntohs(ps_i->length);
|
||||||
if (size < (sizeof(struct ospf_lsupd_packet) + sizeof(struct ospf_lsa_header)))
|
if (size < (sizeof(struct ospf_lsupd_packet) + sizeof(struct ospf_lsa_header)))
|
||||||
{
|
{
|
||||||
log(L_ERR "Bad OSPF LSUPD packet from %I - too short (%u B)", n->ip, size);
|
log(L_ERR "OSPF: Bad LSUPD packet from %I - too short (%u B)", n->ip, size);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -537,7 +534,7 @@ ospf_lsupd_receive(struct ospf_packet *ps_i, struct ospf_iface *ifa,
|
||||||
{
|
{
|
||||||
if (!nifa->iface)
|
if (!nifa->iface)
|
||||||
continue;
|
continue;
|
||||||
if (ipa_equal(nifa->iface->addr->ip, ipa_from_u32(lsatmp.id)))
|
if (ipa_equal(nifa->addr->ip, ipa_from_u32(lsatmp.id)))
|
||||||
{
|
{
|
||||||
self = 1;
|
self = 1;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -450,13 +450,12 @@ bdr_election(struct ospf_iface *ifa)
|
||||||
me.state = NEIGHBOR_2WAY;
|
me.state = NEIGHBOR_2WAY;
|
||||||
me.rid = myid;
|
me.rid = myid;
|
||||||
me.priority = ifa->priority;
|
me.priority = ifa->priority;
|
||||||
|
me.ip = ifa->addr->ip;
|
||||||
|
|
||||||
#ifdef OSPFv2
|
#ifdef OSPFv2
|
||||||
me.ip = ifa->iface->addr->ip;
|
|
||||||
me.dr = ipa_to_u32(ifa->drip);
|
me.dr = ipa_to_u32(ifa->drip);
|
||||||
me.bdr = ipa_to_u32(ifa->bdrip);
|
me.bdr = ipa_to_u32(ifa->bdrip);
|
||||||
#else /* OSPFv3 */
|
#else /* OSPFv3 */
|
||||||
me.ip = ifa->lladdr;
|
|
||||||
me.dr = ifa->drid;
|
me.dr = ifa->drid;
|
||||||
me.bdr = ifa->bdrid;
|
me.bdr = ifa->bdrid;
|
||||||
me.iface_id = ifa->iface->index;
|
me.iface_id = ifa->iface->index;
|
||||||
|
|
|
@ -478,7 +478,9 @@ ospf_shutdown(struct proto *p)
|
||||||
OSPF_TRACE(D_EVENTS, "Shutdown requested");
|
OSPF_TRACE(D_EVENTS, "Shutdown requested");
|
||||||
|
|
||||||
/* And send to all my neighbors 1WAY */
|
/* And send to all my neighbors 1WAY */
|
||||||
WALK_LIST(ifa, po->iface_list) ospf_iface_shutdown(ifa);
|
WALK_LIST(ifa, po->iface_list)
|
||||||
|
if (ifa->state > OSPF_IS_DOWN)
|
||||||
|
ospf_iface_shutdown(ifa);
|
||||||
|
|
||||||
return PS_DOWN;
|
return PS_DOWN;
|
||||||
}
|
}
|
||||||
|
@ -1209,7 +1211,7 @@ show_lsa_sum_net(struct top_hash_entry *he)
|
||||||
lsa_get_ipv6_prefix(ls->prefix, &ip, &pxlen, &pxopts, &rest);
|
lsa_get_ipv6_prefix(ls->prefix, &ip, &pxlen, &pxopts, &rest);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
cli_msg(-1016, "\t\txnetwork %I/%d", ip, pxlen);
|
cli_msg(-1016, "\t\txnetwork %I/%d metric %u", ip, pxlen, ls->metric);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
|
@ -1227,7 +1229,7 @@ show_lsa_sum_rt(struct top_hash_entry *he)
|
||||||
options = ls->options & OPTIONS_MASK;
|
options = ls->options & OPTIONS_MASK;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
cli_msg(-1016, "\t\txrouter %R", dst_rid);
|
cli_msg(-1016, "\t\txrouter %R metric %u", dst_rid, ls->metric);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -159,6 +159,7 @@ struct ospf_iface
|
||||||
{
|
{
|
||||||
node n;
|
node n;
|
||||||
struct iface *iface; /* Nest's iface */
|
struct iface *iface; /* Nest's iface */
|
||||||
|
struct ifa *addr;
|
||||||
struct ospf_area *oa;
|
struct ospf_area *oa;
|
||||||
struct object_lock *lock;
|
struct object_lock *lock;
|
||||||
sock *sk; /* IP socket (for DD ...) */
|
sock *sk; /* IP socket (for DD ...) */
|
||||||
|
@ -192,7 +193,6 @@ struct ospf_iface
|
||||||
u32 dr_iface_id; /* if drid is valid, this is iface_id of DR (for connecting network) */
|
u32 dr_iface_id; /* if drid is valid, this is iface_id of DR (for connecting network) */
|
||||||
u8 instance_id; /* Used to differentiate between more OSPF
|
u8 instance_id; /* Used to differentiate between more OSPF
|
||||||
instances on one interface */
|
instances on one interface */
|
||||||
ip_addr lladdr; /* Used link-local addr */
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
u8 type; /* OSPF view of type */
|
u8 type; /* OSPF view of type */
|
||||||
|
@ -239,7 +239,8 @@ struct ospf_iface
|
||||||
list nbma_list;
|
list nbma_list;
|
||||||
u8 priority; /* A router priority for DR election */
|
u8 priority; /* A router priority for DR election */
|
||||||
u8 ioprob;
|
u8 ioprob;
|
||||||
u8 dr_up; /* Socket is a member of DRouters group */
|
u8 sk_spf; /* Socket is a member of SPFRouters group */
|
||||||
|
u8 sk_dr; /* Socket is a member of DRouters group */
|
||||||
u32 rxbuf;
|
u32 rxbuf;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -675,8 +676,8 @@ struct ospf_neighbor
|
||||||
#define ISM_WAITF 1 /* Wait timer fired */
|
#define ISM_WAITF 1 /* Wait timer fired */
|
||||||
#define ISM_BACKS 2 /* Backup seen */
|
#define ISM_BACKS 2 /* Backup seen */
|
||||||
#define ISM_NEICH 3 /* Neighbor change */
|
#define ISM_NEICH 3 /* Neighbor change */
|
||||||
#define ISM_LOOP 4 /* Loop indicated */
|
// #define ISM_LOOP 4 /* Loop indicated */
|
||||||
#define ISM_UNLOOP 5 /* Unloop indicated */
|
// #define ISM_UNLOOP 5 /* Unloop indicated */
|
||||||
#define ISM_DOWN 6 /* Interface down */
|
#define ISM_DOWN 6 /* Interface down */
|
||||||
|
|
||||||
/* Definitions for neighbor state machine */
|
/* Definitions for neighbor state machine */
|
||||||
|
|
|
@ -255,9 +255,59 @@ ospf_pkt_checkauth(struct ospf_neighbor *n, struct ospf_iface *ifa, struct ospf_
|
||||||
|
|
||||||
#endif
|
#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
|
* ospf_rx_hook
|
||||||
* @sk: socket we received the packet. Its ignored.
|
* @sk: socket we received the packet.
|
||||||
* @size: size of the packet
|
* @size: size of the packet
|
||||||
*
|
*
|
||||||
* This is the entry point for messages from neighbors. Many checks (like
|
* This is the entry point for messages from neighbors. Many checks (like
|
||||||
|
@ -265,21 +315,14 @@ ospf_pkt_checkauth(struct ospf_neighbor *n, struct ospf_iface *ifa, struct ospf_
|
||||||
* non generic functions.
|
* non generic functions.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
ospf_rx_hook(sock * sk, int size)
|
ospf_rx_hook(sock *sk, int size)
|
||||||
{
|
{
|
||||||
struct ospf_packet *ps;
|
char *mesg = "OSPF: Bad packet from ";
|
||||||
struct ospf_iface *ifa = (struct ospf_iface *) (sk->data);
|
|
||||||
struct proto_ospf *po = ifa->oa->po;
|
|
||||||
struct proto *p = &po->proto;
|
|
||||||
struct ospf_neighbor *n;
|
|
||||||
int osize;
|
|
||||||
char *mesg = "Bad OSPF packet from ";
|
|
||||||
struct ospf_iface *iff;
|
|
||||||
|
|
||||||
if (ifa->stub)
|
DBG("OSPF: RX_Hook called (from %I)\n", sk->faddr);
|
||||||
return (1);
|
|
||||||
|
|
||||||
ps = (struct ospf_packet *) ip_skip_header(sk->rbuf, &size);
|
/* First, 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)
|
if (ps == NULL)
|
||||||
{
|
{
|
||||||
|
@ -287,34 +330,25 @@ ospf_rx_hook(sock * sk, int size)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We receive packets related to vlinks even on non-vlink sockets */
|
|
||||||
if ((ifa->oa->areaid != 0) && (ntohl(ps->areaid) == 0))
|
|
||||||
{
|
|
||||||
WALK_LIST(iff, po->iface_list)
|
|
||||||
{
|
|
||||||
if ((iff->type == OSPF_IT_VLINK) && (iff->iface == ifa->iface) &&
|
|
||||||
(iff->voa = ifa->oa) && ipa_equal(sk->faddr, iff->vip))
|
|
||||||
{
|
|
||||||
return 1; /* Packet is for VLINK */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DBG("%s: RX_Hook called on interface %s.\n", p->name, sk->iface->name);
|
|
||||||
|
|
||||||
if ((unsigned) size < sizeof(struct ospf_packet))
|
if ((unsigned) size < sizeof(struct ospf_packet))
|
||||||
{
|
{
|
||||||
log(L_ERR "%s%I - too short (%u bytes)", mesg, sk->faddr, size);
|
log(L_ERR "%s%I - too short (%u bytes)", mesg, sk->faddr, size);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
osize = ntohs(ps->length);
|
int osize = ntohs(ps->length);
|
||||||
if ((osize > size) || ((osize % 4) != 0))
|
if ((osize > size) || ((osize % 4) != 0))
|
||||||
{
|
{
|
||||||
log(L_ERR "%s%I - size field does not match (%d/%d)", mesg, sk->faddr, osize, size);
|
log(L_ERR "%s%I - size field does not match (%d/%d)", mesg, sk->faddr, osize, size);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((unsigned) size > sk->rbsize)
|
||||||
|
{
|
||||||
|
log(L_ERR "%s%I - too large (%d vs %d)", mesg, sk->faddr, size, sk->rbsize);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (ps->version != OSPF_VERSION)
|
if (ps->version != OSPF_VERSION)
|
||||||
{
|
{
|
||||||
log(L_ERR "%s%I - version %u", mesg, sk->faddr, ps->version);
|
log(L_ERR "%s%I - version %u", mesg, sk->faddr, ps->version);
|
||||||
|
@ -331,20 +365,31 @@ ospf_rx_hook(sock * sk, int size)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (ntohl(ps->areaid) != ifa->oa->areaid)
|
|
||||||
|
/* 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)
|
||||||
{
|
{
|
||||||
log(L_ERR "%s%I - different area (%u)", mesg, sk->faddr, ntohl(ps->areaid));
|
/* We limit logging of unmatched packets as it may be perfectly OK */
|
||||||
|
if (unmatched_count < 8)
|
||||||
|
{
|
||||||
|
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++;
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME - handling of instance id should be better */
|
struct proto_ospf *po = ifa->oa->po;
|
||||||
#ifdef OSPFv3
|
struct proto *p = &po->proto;
|
||||||
if (ps->instance_id != ifa->instance_id)
|
|
||||||
{
|
if (ifa->stub) /* This shouldn't happen */
|
||||||
log(L_ERR "%s%I - different instance (%u)", mesg, sk->faddr, ps->instance_id);
|
return 1;
|
||||||
|
|
||||||
|
if (ipa_equal(sk->laddr, AllDRouters) && (ifa->sk_dr == 0))
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (ntohl(ps->routerid) == po->router_id)
|
if (ntohl(ps->routerid) == po->router_id)
|
||||||
{
|
{
|
||||||
|
@ -358,21 +403,15 @@ ospf_rx_hook(sock * sk, int size)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((unsigned) size > sk->rbsize)
|
|
||||||
{
|
|
||||||
log(L_ERR "%s%I - packet is too large (%d vs %d)",
|
|
||||||
mesg, sk->faddr, size, sk->rbsize);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* This is deviation from RFC 2328 - neighbours should be identified by
|
/* This is deviation from RFC 2328 - neighbours should be identified by
|
||||||
* IP address on broadcast and NBMA networks.
|
* IP address on broadcast and NBMA networks.
|
||||||
*/
|
*/
|
||||||
n = find_neigh(ifa, ntohl(ps->routerid));
|
struct ospf_neighbor *n = find_neigh(ifa, ntohl(ps->routerid));
|
||||||
|
|
||||||
if(!n && (ps->type != HELLO_P))
|
if(!n && (ps->type != HELLO_P))
|
||||||
{
|
{
|
||||||
OSPF_TRACE(D_PACKETS, "Received non-hello packet from uknown neighbor (%I)", sk->faddr);
|
log(L_WARN "OSPF: Received non-hello packet from uknown neighbor (src %I, iface %s)",
|
||||||
|
sk->faddr, ifa->iface->name);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,18 +461,17 @@ ospf_rx_hook(sock * sk, int size)
|
||||||
void
|
void
|
||||||
ospf_tx_hook(sock * sk)
|
ospf_tx_hook(sock * sk)
|
||||||
{
|
{
|
||||||
struct ospf_iface *ifa= (struct ospf_iface *) (sk->data);
|
// struct ospf_iface *ifa= (struct ospf_iface *) (sk->data);
|
||||||
struct proto *p = (struct proto *) (ifa->oa->po);
|
// struct proto *p = (struct proto *) (ifa->oa->po);
|
||||||
log(L_ERR "%s: TX_Hook called on interface %s\n", p->name, sk->iface->name);
|
log(L_ERR "OSPF: TX_Hook called");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ospf_err_hook(sock * sk, int err)
|
ospf_err_hook(sock * sk, int err)
|
||||||
{
|
{
|
||||||
struct ospf_iface *ifa= (struct ospf_iface *) (sk->data);
|
// struct ospf_iface *ifa= (struct ospf_iface *) (sk->data);
|
||||||
struct proto *p = (struct proto *) (ifa->oa->po);
|
// struct proto *p = (struct proto *) (ifa->oa->po);
|
||||||
log(L_ERR "%s: Err_Hook called on interface %s with err=%d\n",
|
log(L_ERR "OSPF: Socket error: %m", err);
|
||||||
p->name, sk->iface->name, err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -441,7 +479,8 @@ ospf_send_to_agt(struct ospf_iface *ifa, u8 state)
|
||||||
{
|
{
|
||||||
struct ospf_neighbor *n;
|
struct ospf_neighbor *n;
|
||||||
|
|
||||||
WALK_LIST(n, ifa->neigh_list) if (n->state >= state)
|
WALK_LIST(n, ifa->neigh_list)
|
||||||
|
if (n->state >= state)
|
||||||
ospf_send_to(ifa, n->ip);
|
ospf_send_to(ifa, n->ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -455,7 +494,7 @@ ospf_send_to_bdr(struct ospf_iface *ifa)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ospf_send_to(struct ospf_iface *ifa, ip_addr ip)
|
ospf_send_to(struct ospf_iface *ifa, ip_addr dst)
|
||||||
{
|
{
|
||||||
sock *sk = ifa->sk;
|
sock *sk = ifa->sk;
|
||||||
struct ospf_packet *pkt = (struct ospf_packet *) sk->tbuf;
|
struct ospf_packet *pkt = (struct ospf_packet *) sk->tbuf;
|
||||||
|
@ -468,11 +507,8 @@ ospf_send_to(struct ospf_iface *ifa, ip_addr ip)
|
||||||
|
|
||||||
ospf_pkt_finalize(ifa, pkt);
|
ospf_pkt_finalize(ifa, pkt);
|
||||||
if (sk->tbuf != sk->tpos)
|
if (sk->tbuf != sk->tpos)
|
||||||
log(L_ERR "Aiee, old packet was overwritted in TX buffer");
|
log(L_ERR "Aiee, old packet was overwritten in TX buffer");
|
||||||
|
|
||||||
if (ipa_equal(ip, IPA_NONE))
|
sk_send_to(sk, len, dst, 0);
|
||||||
sk_send(sk, len);
|
|
||||||
else
|
|
||||||
sk_send_to(sk, len, ip, OSPF_PROTO);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,5 +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_bdr(struct ospf_iface *ifa);
|
||||||
void ospf_send_to(struct ospf_iface *ifa, ip_addr ip);
|
void ospf_send_to(struct ospf_iface *ifa, ip_addr ip);
|
||||||
|
|
||||||
|
static inline void * ospf_tx_buffer() { return ospf_socket->tbuf; }
|
||||||
|
|
||||||
#endif /* _BIRD_OSPF_PACKET_H_ */
|
#endif /* _BIRD_OSPF_PACKET_H_ */
|
||||||
|
|
|
@ -266,9 +266,10 @@ ospf_rt_spfa_rtlinks(struct ospf_area *oa, struct top_hash_entry *act, struct to
|
||||||
|
|
||||||
WALK_LIST(iff, po->iface_list) /* Try to find corresponding interface */
|
WALK_LIST(iff, po->iface_list) /* Try to find corresponding interface */
|
||||||
{
|
{
|
||||||
|
// FIXME this is broken
|
||||||
if (iff->iface && (iff->type != OSPF_IT_VLINK) &&
|
if (iff->iface && (iff->type != OSPF_IT_VLINK) &&
|
||||||
(rtl->id == (ipa_to_u32(ipa_mkmask(iff->iface->addr->pxlen))
|
(rtl->id == (ipa_to_u32(ipa_mkmask(iff->addr->pxlen))
|
||||||
& ipa_to_u32(iff->iface->addr->prefix)))) /* No VLINK and IP must match */
|
& ipa_to_u32(iff->addr->prefix)))) /* No VLINK and IP must match */
|
||||||
{
|
{
|
||||||
nf.ifa = iff;
|
nf.ifa = iff;
|
||||||
break;
|
break;
|
||||||
|
@ -428,6 +429,7 @@ ospf_rt_spfa(struct ospf_area *oa)
|
||||||
OSPF_TRACE(D_EVENTS, "Vlink peer %R found", tmp->lsa.id);
|
OSPF_TRACE(D_EVENTS, "Vlink peer %R found", tmp->lsa.id);
|
||||||
ospf_iface_sm(iface, ISM_DOWN);
|
ospf_iface_sm(iface, ISM_DOWN);
|
||||||
iface->iface = tmp->nhi->iface;
|
iface->iface = tmp->nhi->iface;
|
||||||
|
iface->addr = iface->iface->addr;
|
||||||
iface->vip = tmp->lb;
|
iface->vip = tmp->lb;
|
||||||
ospf_iface_sm(iface, ISM_UP);
|
ospf_iface_sm(iface, ISM_UP);
|
||||||
}
|
}
|
||||||
|
@ -569,7 +571,7 @@ ospf_rt_sum_tr(struct ospf_area *oa)
|
||||||
metric = ls->metric & METRIC_MASK;
|
metric = ls->metric & METRIC_MASK;
|
||||||
options = 0;
|
options = 0;
|
||||||
type = ORT_NET;
|
type = ORT_NET;
|
||||||
re = (ort *) fib_find(&po->rtf, &ip, pxlen);
|
re = fib_find(&po->rtf, &ip, pxlen);
|
||||||
}
|
}
|
||||||
else if (en->lsa.type == LSA_T_SUM_RT)
|
else if (en->lsa.type == LSA_T_SUM_RT)
|
||||||
{
|
{
|
||||||
|
@ -588,7 +590,7 @@ ospf_rt_sum_tr(struct ospf_area *oa)
|
||||||
metric = ls->metric & METRIC_MASK;
|
metric = ls->metric & METRIC_MASK;
|
||||||
options |= ORTA_ASBR;
|
options |= ORTA_ASBR;
|
||||||
type = ORT_ROUTER;
|
type = ORT_ROUTER;
|
||||||
re = (ort *) fib_find(&bb->rtr, &ip, pxlen);
|
re = fib_find(&bb->rtr, &ip, pxlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 16.3 (1b) */
|
/* 16.3 (1b) */
|
||||||
|
@ -596,14 +598,14 @@ ospf_rt_sum_tr(struct ospf_area *oa)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* 16.3 (3) */
|
/* 16.3 (3) */
|
||||||
if (!re) continue;
|
if (!re || !re->n.type) continue;
|
||||||
if (re->n.oa->areaid != 0) continue;
|
if (re->n.oa->areaid != 0) continue;
|
||||||
if ((re->n.type != RTS_OSPF) && (re->n.type != RTS_OSPF_IA)) continue;
|
if ((re->n.type != RTS_OSPF) && (re->n.type != RTS_OSPF_IA)) continue;
|
||||||
|
|
||||||
/* 16.3. (4) */
|
/* 16.3. (4) */
|
||||||
abrip = ipa_from_rid(en->lsa.rt);
|
abrip = ipa_from_rid(en->lsa.rt);
|
||||||
abr = fib_find(&oa->rtr, &abrip, MAX_PREFIX_LENGTH);
|
abr = fib_find(&oa->rtr, &abrip, MAX_PREFIX_LENGTH);
|
||||||
if (!abr) continue;
|
if (!abr || !abr->n.type) continue;
|
||||||
|
|
||||||
nf.type = re->n.type;
|
nf.type = re->n.type;
|
||||||
nf.options = options;
|
nf.options = options;
|
||||||
|
@ -711,7 +713,9 @@ ospf_rt_sum(struct ospf_area *oa)
|
||||||
|
|
||||||
/* Page 169 (4) */
|
/* Page 169 (4) */
|
||||||
abrip = ipa_from_rid(en->lsa.rt);
|
abrip = ipa_from_rid(en->lsa.rt);
|
||||||
if (!(abr = (ort *) fib_find(&oa->rtr, &abrip, MAX_PREFIX_LENGTH))) continue;
|
|
||||||
|
abr = (ort *) fib_find(&oa->rtr, &abrip, MAX_PREFIX_LENGTH);
|
||||||
|
if (!abr || !abr->n.type) continue;
|
||||||
if (abr->n.metric1 == LSINFINITY) continue;
|
if (abr->n.metric1 == LSINFINITY) continue;
|
||||||
if (!(abr->n.options & ORTA_ABR)) continue;
|
if (!(abr->n.options & ORTA_ABR)) continue;
|
||||||
|
|
||||||
|
@ -901,7 +905,7 @@ ospf_ext_spf(struct proto_ospf *po)
|
||||||
WALK_LIST(atmp, po->area_list)
|
WALK_LIST(atmp, po->area_list)
|
||||||
{
|
{
|
||||||
nfh = fib_find(&atmp->rtr, &rtid, MAX_PREFIX_LENGTH);
|
nfh = fib_find(&atmp->rtr, &rtid, MAX_PREFIX_LENGTH);
|
||||||
if (nfh == NULL) continue;
|
if (!nfh || !nfh->n.type) continue;
|
||||||
if (nf1 == NULL) nf1 = nfh;
|
if (nf1 == NULL) nf1 = nfh;
|
||||||
else if (ri_better(po, &nfh->n, NULL, &nf1->n, NULL, po->rfc1583)) nf1 = nfh;
|
else if (ri_better(po, &nfh->n, NULL, &nf1->n, NULL, po->rfc1583)) nf1 = nfh;
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,7 +205,7 @@ originate_rt_lsa_body(struct ospf_area *oa, u16 *length)
|
||||||
|
|
||||||
WALK_LIST(ifa, po->iface_list)
|
WALK_LIST(ifa, po->iface_list)
|
||||||
{
|
{
|
||||||
int master = 0;
|
int net_lsa = 0;
|
||||||
|
|
||||||
if ((ifa->type == OSPF_IT_VLINK) && (ifa->voa == oa) &&
|
if ((ifa->type == OSPF_IT_VLINK) && (ifa->voa == oa) &&
|
||||||
(!EMPTY_LIST(ifa->neigh_list)))
|
(!EMPTY_LIST(ifa->neigh_list)))
|
||||||
|
@ -230,12 +230,11 @@ originate_rt_lsa_body(struct ospf_area *oa, u16 *length)
|
||||||
ln = lsab_alloc(po, sizeof(struct ospf_lsa_rt_link));
|
ln = lsab_alloc(po, sizeof(struct ospf_lsa_rt_link));
|
||||||
ln->type = LSART_PTP;
|
ln->type = LSART_PTP;
|
||||||
ln->id = neigh->rid;
|
ln->id = neigh->rid;
|
||||||
ln->data = (ifa->iface->addr->flags & IA_UNNUMBERED) ?
|
ln->data = (ifa->addr->flags & IA_UNNUMBERED) ?
|
||||||
ifa->iface->index : ipa_to_u32(ifa->iface->addr->ip);
|
ifa->iface->index : ipa_to_u32(ifa->addr->ip);
|
||||||
ln->metric = ifa->cost;
|
ln->metric = ifa->cost;
|
||||||
ln->padding = 0;
|
ln->padding = 0;
|
||||||
i++;
|
i++;
|
||||||
master = 1;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -246,11 +245,11 @@ originate_rt_lsa_body(struct ospf_area *oa, u16 *length)
|
||||||
ln = lsab_alloc(po, sizeof(struct ospf_lsa_rt_link));
|
ln = lsab_alloc(po, sizeof(struct ospf_lsa_rt_link));
|
||||||
ln->type = LSART_NET;
|
ln->type = LSART_NET;
|
||||||
ln->id = ipa_to_u32(ifa->drip);
|
ln->id = ipa_to_u32(ifa->drip);
|
||||||
ln->data = ipa_to_u32(ifa->iface->addr->ip);
|
ln->data = ipa_to_u32(ifa->addr->ip);
|
||||||
ln->metric = ifa->cost;
|
ln->metric = ifa->cost;
|
||||||
ln->padding = 0;
|
ln->padding = 0;
|
||||||
i++;
|
i++;
|
||||||
master = 1;
|
net_lsa = 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -261,11 +260,10 @@ originate_rt_lsa_body(struct ospf_area *oa, u16 *length)
|
||||||
ln = lsab_alloc(po, sizeof(struct ospf_lsa_rt_link));
|
ln = lsab_alloc(po, sizeof(struct ospf_lsa_rt_link));
|
||||||
ln->type = LSART_VLNK;
|
ln->type = LSART_VLNK;
|
||||||
ln->id = neigh->rid;
|
ln->id = neigh->rid;
|
||||||
ln->data = ipa_to_u32(ifa->iface->addr->ip);
|
ln->data = ipa_to_u32(ifa->addr->ip);
|
||||||
ln->metric = ifa->cost;
|
ln->metric = ifa->cost;
|
||||||
ln->padding = 0;
|
ln->padding = 0;
|
||||||
i++;
|
i++;
|
||||||
master = 1;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -278,13 +276,12 @@ originate_rt_lsa_body(struct ospf_area *oa, u16 *length)
|
||||||
struct ifa *a;
|
struct ifa *a;
|
||||||
WALK_LIST(a, ifa->iface->addrs)
|
WALK_LIST(a, ifa->iface->addrs)
|
||||||
{
|
{
|
||||||
if (((a == ifa->iface->addr) && master) ||
|
if (((a == ifa->addr) && net_lsa) ||
|
||||||
(a->flags & IA_SECONDARY) ||
|
(a->flags & IA_SECONDARY) ||
|
||||||
(a->flags & IA_UNNUMBERED) ||
|
(a->flags & IA_UNNUMBERED) ||
|
||||||
configured_stubnet(oa, a))
|
configured_stubnet(oa, a))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
||||||
ln = lsab_alloc(po, sizeof(struct ospf_lsa_rt_link));
|
ln = lsab_alloc(po, sizeof(struct ospf_lsa_rt_link));
|
||||||
ln->type = LSART_STUB;
|
ln->type = LSART_STUB;
|
||||||
ln->id = ipa_to_u32(a->prefix);
|
ln->id = ipa_to_u32(a->prefix);
|
||||||
|
@ -483,7 +480,7 @@ originate_net_lsa_body(struct ospf_iface *ifa, u16 *length,
|
||||||
+ nodes * sizeof(u32));
|
+ nodes * sizeof(u32));
|
||||||
|
|
||||||
#ifdef OSPFv2
|
#ifdef OSPFv2
|
||||||
net->netmask = ipa_mkmask(ifa->iface->addr->pxlen);
|
net->netmask = ipa_mkmask(ifa->addr->pxlen);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef OSPFv3
|
#ifdef OSPFv3
|
||||||
|
@ -547,7 +544,7 @@ originate_net_lsa(struct ospf_iface *ifa)
|
||||||
|
|
||||||
#ifdef OSPFv2
|
#ifdef OSPFv2
|
||||||
lsa.options = ifa->oa->options;
|
lsa.options = ifa->oa->options;
|
||||||
lsa.id = ipa_to_u32(ifa->iface->addr->ip);
|
lsa.id = ipa_to_u32(ifa->addr->ip);
|
||||||
#else /* OSPFv3 */
|
#else /* OSPFv3 */
|
||||||
lsa.id = ifa->iface->index;
|
lsa.id = ifa->iface->index;
|
||||||
#endif
|
#endif
|
||||||
|
@ -750,11 +747,12 @@ originate_sum_rt_lsa(struct ospf_area *oa, struct fib_node *fn, int metric, u32
|
||||||
struct proto *p = &po->proto;
|
struct proto *p = &po->proto;
|
||||||
struct top_hash_entry *en;
|
struct top_hash_entry *en;
|
||||||
u32 dom = oa->areaid;
|
u32 dom = oa->areaid;
|
||||||
|
u32 rid = ipa_to_rid(fn->prefix);
|
||||||
struct ospf_lsa_header lsa;
|
struct ospf_lsa_header lsa;
|
||||||
void *body;
|
void *body;
|
||||||
|
|
||||||
OSPF_TRACE(D_EVENTS, "Originating rt-summary-LSA for %R (metric %d)",
|
OSPF_TRACE(D_EVENTS, "Originating rt-summary-LSA for %R (metric %d)",
|
||||||
lsa.id, metric);
|
rid, metric);
|
||||||
|
|
||||||
lsa.age = 0;
|
lsa.age = 0;
|
||||||
#ifdef OSPFv2
|
#ifdef OSPFv2
|
||||||
|
@ -762,7 +760,7 @@ originate_sum_rt_lsa(struct ospf_area *oa, struct fib_node *fn, int metric, u32
|
||||||
#endif
|
#endif
|
||||||
lsa.type = LSA_T_SUM_RT;
|
lsa.type = LSA_T_SUM_RT;
|
||||||
/* In OSPFv3, LSA ID is meaningless, but we still use Router ID of ASBR */
|
/* In OSPFv3, LSA ID is meaningless, but we still use Router ID of ASBR */
|
||||||
lsa.id = ipa_to_rid(fn->prefix);
|
lsa.id = rid;
|
||||||
lsa.rt = po->router_id;
|
lsa.rt = po->router_id;
|
||||||
lsa.sn = LSA_INITSEQNO;
|
lsa.sn = LSA_INITSEQNO;
|
||||||
|
|
||||||
|
@ -1052,7 +1050,7 @@ originate_link_lsa_body(struct ospf_iface *ifa, u16 *length)
|
||||||
ASSERT(po->lsab_used == 0);
|
ASSERT(po->lsab_used == 0);
|
||||||
ll = lsab_allocz(po, sizeof(struct ospf_lsa_link));
|
ll = lsab_allocz(po, sizeof(struct ospf_lsa_link));
|
||||||
ll->options = ifa->oa->options | (ifa->priority << 24);
|
ll->options = ifa->oa->options | (ifa->priority << 24);
|
||||||
ll->lladdr = ifa->lladdr;
|
ll->lladdr = ifa->addr->ip;
|
||||||
ll = NULL; /* buffer might be reallocated later */
|
ll = NULL; /* buffer might be reallocated later */
|
||||||
|
|
||||||
struct ifa *a;
|
struct ifa *a;
|
||||||
|
|
|
@ -15,9 +15,17 @@ set_inaddr(struct in6_addr * ia, ip_addr a)
|
||||||
memcpy(ia, &a, sizeof(a));
|
memcpy(ia, &a, sizeof(a));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
get_inaddr(ip_addr *a, struct in6_addr *ia)
|
||||||
|
{
|
||||||
|
memcpy(a, ia, sizeof(*a));
|
||||||
|
ipa_ntoh(*a);
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
|
#include <net/if_dl.h>
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
set_inaddr(struct in_addr * ia, ip_addr a)
|
set_inaddr(struct in_addr * ia, ip_addr a)
|
||||||
|
@ -26,6 +34,16 @@ set_inaddr(struct in_addr * ia, ip_addr a)
|
||||||
memcpy(&ia->s_addr, &a, sizeof(a));
|
memcpy(&ia->s_addr, &a, sizeof(a));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
get_inaddr(ip_addr *a, struct in_addr *ia)
|
||||||
|
{
|
||||||
|
memcpy(a, &ia->s_addr, sizeof(*a));
|
||||||
|
ipa_ntoh(*a);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* BSD Multicast handling for IPv4 */
|
||||||
|
|
||||||
static inline char *
|
static inline char *
|
||||||
sysio_setup_multicast(sock *s)
|
sysio_setup_multicast(sock *s)
|
||||||
{
|
{
|
||||||
|
@ -80,6 +98,90 @@ sysio_leave_group(sock *s, ip_addr maddr)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* BSD RX/TX packet info handling for IPv4 */
|
||||||
|
/* it uses IP_RECVDSTADDR / IP_RECVIF socket options instead of IP_PKTINFO */
|
||||||
|
|
||||||
|
#define CMSG_RX_SPACE (CMSG_SPACE(sizeof(struct in_addr)) + CMSG_SPACE(sizeof(struct sockaddr_dl)))
|
||||||
|
#define CMSG_TX_SPACE CMSG_SPACE(sizeof(struct in_addr))
|
||||||
|
|
||||||
|
static char *
|
||||||
|
sysio_register_cmsgs(sock *s)
|
||||||
|
{
|
||||||
|
int ok = 1;
|
||||||
|
if (s->flags & SKF_LADDR_RX)
|
||||||
|
{
|
||||||
|
if (setsockopt(s->fd, IPPROTO_IP, IP_RECVDSTADDR, &ok, sizeof(ok)) < 0)
|
||||||
|
return "IP_RECVDSTADDR";
|
||||||
|
|
||||||
|
if (setsockopt(s->fd, IPPROTO_IP, IP_RECVIF, &ok, sizeof(ok)) < 0)
|
||||||
|
return "IP_RECVIF";
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sysio_process_rx_cmsgs(sock *s, struct msghdr *msg)
|
||||||
|
{
|
||||||
|
struct cmsghdr *cm;
|
||||||
|
|
||||||
|
if (!(s->flags & SKF_LADDR_RX))
|
||||||
|
return;
|
||||||
|
|
||||||
|
s->laddr = IPA_NONE;
|
||||||
|
s->lifindex = 0;
|
||||||
|
|
||||||
|
for (cm = CMSG_FIRSTHDR(msg); cm != NULL; cm = CMSG_NXTHDR(msg, cm))
|
||||||
|
{
|
||||||
|
if (cm->cmsg_level == IPPROTO_IP && cm->cmsg_type == IP_RECVDSTADDR)
|
||||||
|
{
|
||||||
|
struct in_addr *ra = (struct in_addr *) CMSG_DATA(cm);
|
||||||
|
get_inaddr(&s->laddr, ra);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cm->cmsg_level == IPPROTO_IP && cm->cmsg_type == IP_RECVIF)
|
||||||
|
{
|
||||||
|
struct sockaddr_dl *ri = (struct sockaddr_dl *) CMSG_DATA(cm);
|
||||||
|
s->lifindex = ri->sdl_index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// log(L_WARN "RX %I %d", s->laddr, s->lifindex);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
sysio_prepare_tx_cmsgs(sock *s, struct msghdr *msg)
|
||||||
|
{
|
||||||
|
struct cmsghdr *cm;
|
||||||
|
struct in_addr *sa;
|
||||||
|
|
||||||
|
if (!(s->flags & SKF_LADDR_TX))
|
||||||
|
{
|
||||||
|
msg->msg_controllen = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (s->iface)
|
||||||
|
{
|
||||||
|
struct in_addr m;
|
||||||
|
// set_inaddr(&m, s->iface->addr->ip);
|
||||||
|
set_inaddr(&m, s->saddr);
|
||||||
|
setsockopt(s->fd, IPPROTO_IP, IP_MULTICAST_IF, &m, sizeof(m));
|
||||||
|
}
|
||||||
|
|
||||||
|
cm = CMSG_FIRSTHDR(msg);
|
||||||
|
cm->cmsg_level = IPPROTO_IP;
|
||||||
|
cm->cmsg_type = IP_SENDSRCADDR;
|
||||||
|
cm->cmsg_len = CMSG_LEN(sizeof(*sa));
|
||||||
|
|
||||||
|
sa = (struct in_addr *) CMSG_DATA(cm);
|
||||||
|
set_inaddr(sa, s->saddr);
|
||||||
|
|
||||||
|
msg->msg_controllen = cm->cmsg_len;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,13 @@ set_inaddr(struct in6_addr *ia, ip_addr a)
|
||||||
memcpy(ia, &a, sizeof(a));
|
memcpy(ia, &a, sizeof(a));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
get_inaddr(ip_addr *a, struct in6_addr *ia)
|
||||||
|
{
|
||||||
|
memcpy(a, ia, sizeof(*a));
|
||||||
|
ipa_ntoh(*a);
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
|
@ -32,6 +39,13 @@ set_inaddr(struct in_addr *ia, ip_addr a)
|
||||||
memcpy(&ia->s_addr, &a, sizeof(a));
|
memcpy(&ia->s_addr, &a, sizeof(a));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
get_inaddr(ip_addr *a, struct in_addr *ia)
|
||||||
|
{
|
||||||
|
memcpy(a, &ia->s_addr, sizeof(*a));
|
||||||
|
ipa_ntoh(*a);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Multicasting in Linux systems is a real mess. Not only different kernels
|
* Multicasting in Linux systems is a real mess. Not only different kernels
|
||||||
* have different interfaces, but also different libc's export it in different
|
* have different interfaces, but also different libc's export it in different
|
||||||
|
@ -209,3 +223,76 @@ sk_set_md5_auth_int(sock *s, sockaddr *sa, char *passwd)
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef IPV6
|
||||||
|
|
||||||
|
/* RX/TX packet info handling for IPv4 */
|
||||||
|
/* Mostly similar to standardized IPv6 code */
|
||||||
|
|
||||||
|
#define CMSG_RX_SPACE CMSG_SPACE(sizeof(struct in_pktinfo))
|
||||||
|
#define CMSG_TX_SPACE CMSG_SPACE(sizeof(struct in_pktinfo))
|
||||||
|
|
||||||
|
static char *
|
||||||
|
sysio_register_cmsgs(sock *s)
|
||||||
|
{
|
||||||
|
int ok = 1;
|
||||||
|
if ((s->flags & SKF_LADDR_RX) &&
|
||||||
|
setsockopt(s->fd, IPPROTO_IP, IP_PKTINFO, &ok, sizeof(ok)) < 0)
|
||||||
|
return "IP_PKTINFO";
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sysio_process_rx_cmsgs(sock *s, struct msghdr *msg)
|
||||||
|
{
|
||||||
|
struct cmsghdr *cm;
|
||||||
|
struct in_pktinfo *pi = NULL;
|
||||||
|
|
||||||
|
if (!(s->flags & SKF_LADDR_RX))
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (cm = CMSG_FIRSTHDR(msg); cm != NULL; cm = CMSG_NXTHDR(msg, cm))
|
||||||
|
{
|
||||||
|
if (cm->cmsg_level == IPPROTO_IP && cm->cmsg_type == IP_PKTINFO)
|
||||||
|
pi = (struct in_pktinfo *) CMSG_DATA(cm);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pi)
|
||||||
|
{
|
||||||
|
s->laddr = IPA_NONE;
|
||||||
|
s->lifindex = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
get_inaddr(&s->laddr, &pi->ipi_addr);
|
||||||
|
s->lifindex = pi->ipi_ifindex;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
sysio_prepare_tx_cmsgs(sock *s, struct msghdr *msg)
|
||||||
|
{
|
||||||
|
struct cmsghdr *cm;
|
||||||
|
struct in_pktinfo *pi;
|
||||||
|
|
||||||
|
if (!(s->flags & SKF_LADDR_TX))
|
||||||
|
{
|
||||||
|
msg->msg_controllen = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cm = CMSG_FIRSTHDR(msg);
|
||||||
|
cm->cmsg_level = IPPROTO_IP;
|
||||||
|
cm->cmsg_type = IP_PKTINFO;
|
||||||
|
cm->cmsg_len = CMSG_LEN(sizeof(*pi));
|
||||||
|
|
||||||
|
pi = (struct in_pktinfo *) CMSG_DATA(cm);
|
||||||
|
set_inaddr(&pi->ipi_spec_dst, s->saddr);
|
||||||
|
pi->ipi_ifindex = s->iface ? s->iface->index : 0;
|
||||||
|
|
||||||
|
msg->msg_controllen = cm->cmsg_len;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
143
sysdep/unix/io.c
143
sysdep/unix/io.c
|
@ -682,7 +682,7 @@ static char *
|
||||||
sk_setup(sock *s)
|
sk_setup(sock *s)
|
||||||
{
|
{
|
||||||
int fd = s->fd;
|
int fd = s->fd;
|
||||||
char *err;
|
char *err = NULL;
|
||||||
|
|
||||||
if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
|
if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
|
||||||
ERR("fcntl(O_NONBLOCK)");
|
ERR("fcntl(O_NONBLOCK)");
|
||||||
|
@ -701,9 +701,8 @@ sk_setup(sock *s)
|
||||||
|
|
||||||
if (s->ttl >= 0)
|
if (s->ttl >= 0)
|
||||||
err = sk_set_ttl_int(s);
|
err = sk_set_ttl_int(s);
|
||||||
else
|
|
||||||
err = NULL;
|
|
||||||
|
|
||||||
|
sysio_register_cmsgs(s);
|
||||||
bad:
|
bad:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -854,6 +853,72 @@ sk_leave_group(sock *s, ip_addr maddr)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* PKTINFO handling is also standardized in IPv6 */
|
||||||
|
#define CMSG_RX_SPACE CMSG_SPACE(sizeof(struct in6_pktinfo))
|
||||||
|
|
||||||
|
static char *
|
||||||
|
sysio_register_cmsgs(sock *s)
|
||||||
|
{
|
||||||
|
int ok = 1;
|
||||||
|
if ((s->flags & SKF_LADDR_RX) &&
|
||||||
|
setsockopt(s->fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, &ok, sizeof(ok)) < 0)
|
||||||
|
return "IPV6_RECVPKTINFO";
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sysio_process_rx_cmsgs(sock *s, struct msghdr *msg)
|
||||||
|
{
|
||||||
|
struct cmsghdr *cm;
|
||||||
|
struct in6_pktinfo *pi = NULL;
|
||||||
|
|
||||||
|
if (!(s->flags & SKF_LADDR_RX))
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (cm = CMSG_FIRSTHDR(msg); cm != NULL; cm = CMSG_NXTHDR(msg, cm))
|
||||||
|
{
|
||||||
|
if (cm->cmsg_level == IPPROTO_IPV6 && cm->cmsg_type == IPV6_PKTINFO)
|
||||||
|
pi = (struct in6_pktinfo *) CMSG_DATA(cm);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pi)
|
||||||
|
{
|
||||||
|
s->laddr = IPA_NONE;
|
||||||
|
s->lifindex = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
get_inaddr(&s->laddr, &pi->ipi6_addr);
|
||||||
|
s->lifindex = pi->ipi6_ifindex;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
sysio_prepare_tx_cmsgs(sock *s, struct msghdr *msg)
|
||||||
|
{
|
||||||
|
struct cmsghdr *cm;
|
||||||
|
struct in6_pktinfo *pi;
|
||||||
|
|
||||||
|
if (!(s->flags & SKF_LADDR_TX))
|
||||||
|
{
|
||||||
|
msg->msg_controllen = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cm = CMSG_FIRSTHDR(msg);
|
||||||
|
cm->cmsg_level = IPPROTO_IPV6;
|
||||||
|
cm->cmsg_type = PIV6_PKTINFO;
|
||||||
|
cm->cmsg_len = CMSG_LEN(sizeof(*pi));
|
||||||
|
|
||||||
|
pi = (struct in6_pktinfo *) CMSG_DATA(cm);
|
||||||
|
set_inaddr(&pi->ipi6_addr, s->saddr);
|
||||||
|
pi->ipi6_ifindex = s->iface ? s->iface->index : 0;
|
||||||
|
|
||||||
|
msg->msg_controllen = cmsg->cmsg_len;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
#else /* IPV4 */
|
#else /* IPV4 */
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -1107,6 +1172,8 @@ bad:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void reset_tx_buffer(sock *s) { s->ttx = s->tpos = s->tbuf; }
|
||||||
|
|
||||||
static int
|
static int
|
||||||
sk_maybe_write(sock *s)
|
sk_maybe_write(sock *s)
|
||||||
{
|
{
|
||||||
|
@ -1124,7 +1191,7 @@ sk_maybe_write(sock *s)
|
||||||
{
|
{
|
||||||
if (errno != EINTR && errno != EAGAIN)
|
if (errno != EINTR && errno != EAGAIN)
|
||||||
{
|
{
|
||||||
s->ttx = s->tpos; /* empty tx buffer */
|
reset_tx_buffer(s);
|
||||||
s->err_hook(s, errno);
|
s->err_hook(s, errno);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -1132,30 +1199,44 @@ sk_maybe_write(sock *s)
|
||||||
}
|
}
|
||||||
s->ttx += e;
|
s->ttx += e;
|
||||||
}
|
}
|
||||||
s->ttx = s->tpos = s->tbuf;
|
reset_tx_buffer(s);
|
||||||
return 1;
|
return 1;
|
||||||
case SK_UDP:
|
case SK_UDP:
|
||||||
case SK_IP:
|
case SK_IP:
|
||||||
{
|
{
|
||||||
sockaddr sa;
|
|
||||||
|
|
||||||
if (s->tbuf == s->tpos)
|
if (s->tbuf == s->tpos)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
fill_in_sockaddr(&sa, s->faddr, s->fport);
|
sockaddr sa;
|
||||||
|
fill_in_sockaddr(&sa, s->daddr, s->dport);
|
||||||
fill_in_sockifa(&sa, s->iface);
|
fill_in_sockifa(&sa, s->iface);
|
||||||
e = sendto(s->fd, s->tbuf, s->tpos - s->tbuf, 0, (struct sockaddr *) &sa, sizeof(sa));
|
|
||||||
|
struct iovec iov = {s->tbuf, s->tpos - s->tbuf};
|
||||||
|
byte cmsg_buf[CMSG_TX_SPACE];
|
||||||
|
|
||||||
|
struct msghdr msg = {
|
||||||
|
.msg_name = &sa,
|
||||||
|
.msg_namelen = sizeof(sa),
|
||||||
|
.msg_iov = &iov,
|
||||||
|
.msg_iovlen = 1,
|
||||||
|
.msg_control = cmsg_buf,
|
||||||
|
.msg_controllen = sizeof(cmsg_buf),
|
||||||
|
.msg_flags = 0};
|
||||||
|
|
||||||
|
sysio_prepare_tx_cmsgs(s, &msg);
|
||||||
|
e = sendmsg(s->fd, &msg, 0);
|
||||||
|
|
||||||
if (e < 0)
|
if (e < 0)
|
||||||
{
|
{
|
||||||
if (errno != EINTR && errno != EAGAIN)
|
if (errno != EINTR && errno != EAGAIN)
|
||||||
{
|
{
|
||||||
s->ttx = s->tpos; /* empty tx buffer */
|
reset_tx_buffer(s);
|
||||||
s->err_hook(s, errno);
|
s->err_hook(s, errno);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
s->tpos = s->tbuf;
|
reset_tx_buffer(s);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -1201,8 +1282,6 @@ sk_rx_ready(sock *s)
|
||||||
int
|
int
|
||||||
sk_send(sock *s, unsigned len)
|
sk_send(sock *s, unsigned len)
|
||||||
{
|
{
|
||||||
s->faddr = s->daddr;
|
|
||||||
s->fport = s->dport;
|
|
||||||
s->ttx = s->tbuf;
|
s->ttx = s->tbuf;
|
||||||
s->tpos = s->tbuf + len;
|
s->tpos = s->tbuf + len;
|
||||||
return sk_maybe_write(s);
|
return sk_maybe_write(s);
|
||||||
|
@ -1221,13 +1300,28 @@ sk_send(sock *s, unsigned len)
|
||||||
int
|
int
|
||||||
sk_send_to(sock *s, unsigned len, ip_addr addr, unsigned port)
|
sk_send_to(sock *s, unsigned len, ip_addr addr, unsigned port)
|
||||||
{
|
{
|
||||||
s->faddr = addr;
|
s->daddr = addr;
|
||||||
s->fport = port;
|
s->dport = port;
|
||||||
s->ttx = s->tbuf;
|
s->ttx = s->tbuf;
|
||||||
s->tpos = s->tbuf + len;
|
s->tpos = s->tbuf + len;
|
||||||
return sk_maybe_write(s);
|
return sk_maybe_write(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
int
|
||||||
|
sk_send_full(sock *s, unsigned len, struct iface *ifa,
|
||||||
|
ip_addr saddr, ip_addr daddr, unsigned dport)
|
||||||
|
{
|
||||||
|
s->iface = ifa;
|
||||||
|
s->saddr = saddr;
|
||||||
|
s->daddr = daddr;
|
||||||
|
s->dport = dport;
|
||||||
|
s->ttx = s->tbuf;
|
||||||
|
s->tpos = s->tbuf + len;
|
||||||
|
return sk_maybe_write(s);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
static int
|
static int
|
||||||
sk_read(sock *s)
|
sk_read(sock *s)
|
||||||
{
|
{
|
||||||
|
@ -1273,8 +1367,21 @@ sk_read(sock *s)
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
sockaddr sa;
|
sockaddr sa;
|
||||||
int al = sizeof(sa);
|
int e;
|
||||||
int e = recvfrom(s->fd, s->rbuf, s->rbsize, 0, (struct sockaddr *) &sa, &al);
|
|
||||||
|
struct iovec iov = {s->rbuf, s->rbsize};
|
||||||
|
byte cmsg_buf[CMSG_RX_SPACE];
|
||||||
|
|
||||||
|
struct msghdr msg = {
|
||||||
|
.msg_name = &sa,
|
||||||
|
.msg_namelen = sizeof(sa),
|
||||||
|
.msg_iov = &iov,
|
||||||
|
.msg_iovlen = 1,
|
||||||
|
.msg_control = cmsg_buf,
|
||||||
|
.msg_controllen = sizeof(cmsg_buf),
|
||||||
|
.msg_flags = 0};
|
||||||
|
|
||||||
|
e = recvmsg(s->fd, &msg, 0);
|
||||||
|
|
||||||
if (e < 0)
|
if (e < 0)
|
||||||
{
|
{
|
||||||
|
@ -1284,6 +1391,8 @@ sk_read(sock *s)
|
||||||
}
|
}
|
||||||
s->rpos = s->rbuf + e;
|
s->rpos = s->rbuf + e;
|
||||||
get_sockaddr(&sa, &s->faddr, &s->fport, 1);
|
get_sockaddr(&sa, &s->faddr, &s->fport, 1);
|
||||||
|
sysio_process_rx_cmsgs(s, &msg);
|
||||||
|
|
||||||
s->rx_hook(s, e);
|
s->rx_hook(s, e);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue