Commit 0aad2b92 authored by Ondřej Zajíček's avatar Ondřej Zajíček

Temporary OSPF commit - sockets.

parent 54305181
......@@ -566,8 +566,8 @@ if_init(void)
* Interface Pattern Lists
*/
static int
iface_patt_match(struct iface_patt *ifp, struct iface *i)
int
iface_patt_match(struct iface_patt *ifp, struct iface *i, struct ifa *a)
{
struct iface_patt_node *p;
......@@ -588,8 +588,9 @@ iface_patt_match(struct iface_patt *ifp, struct iface *i)
continue;
}
// FIXME there should be check for prefix in prefix. (?)
if (p->pxlen)
if (!i->addr || !ipa_in_net(i->addr->ip, p->prefix, p->pxlen))
if (!a || !ipa_in_net(a->ip, p->prefix, p->pxlen))
continue;
return pos;
......@@ -599,12 +600,12 @@ iface_patt_match(struct iface_patt *ifp, struct iface *i)
}
struct iface_patt *
iface_patt_find(list *l, struct iface *i)
iface_patt_find(list *l, struct iface *i, struct ifa *a)
{
struct iface_patt *p;
WALK_LIST(p, *l)
if (iface_patt_match(p, i))
if (iface_patt_match(p, i, a))
return p;
return NULL;
......
......@@ -144,7 +144,8 @@ struct iface_patt {
/* Protocol-specific data follow after this structure */
};
struct iface_patt *iface_patt_find(list *, struct iface *);
int iface_patt_match(struct iface_patt *ifp, struct iface *i, struct ifa *a);
struct iface_patt *iface_patt_find(list *l, struct iface *i, struct ifa *a);
int iface_patts_equal(list *, list *, int (*)(struct iface_patt *, struct iface_patt *));
#endif
......@@ -30,7 +30,7 @@ dev_ifa_notify(struct proto *p, unsigned c, struct ifa *ad)
struct rt_dev_config *P = (void *) p->cf;
if (!EMPTY_LIST(P->iface_list) &&
!iface_patt_find(&P->iface_list, ad->iface))
!iface_patt_find(&P->iface_list, ad->iface, ad->iface->addr))
/* Empty list is automagically treated as "*" */
return;
......
......@@ -254,8 +254,8 @@ ospf_hello_send(timer *timer, int poll, struct ospf_neighbor *dirn)
return; /* Don't send any packet on stub iface */
p = (struct proto *) (ifa->oa->po);
DBG("%s: Hello/Poll timer fired on interface %s.\n",
p->name, ifa->iface->name);
DBG("%s: Hello/Poll timer fired on interface %s with IP %I\n",
p->name, ifa->iface->name, ifa->addr->ip);
/* Now we should send a hello packet */
pkt = ospf_tx_buffer(ifa);
......
This diff is collapsed.
......@@ -14,9 +14,10 @@ void ospf_iface_chstate(struct ospf_iface *ifa, u8 state);
void ospf_iface_sm(struct ospf_iface *ifa, int event);
struct ospf_iface *ospf_iface_find(struct proto_ospf *p, struct iface *what);
void ospf_iface_notify(struct proto *p, unsigned flags, struct iface *iface);
void ospf_ifa_notify(struct proto *p, unsigned flags, struct ifa *a);
void ospf_iface_info(struct ospf_iface *ifa);
void ospf_iface_shutdown(struct ospf_iface *ifa);
void ospf_iface_new(struct proto_ospf *po, struct iface *iface, struct ospf_area_config *ac, struct ospf_iface_patt *ip);
void ospf_iface_new(struct proto_ospf *po, struct iface *iface, struct ifa *addr, struct ospf_area_config *ac, struct ospf_iface_patt *ip);
void ospf_iface_change_mtu(struct proto_ospf *po, struct ospf_iface *ifa);
void ospf_set_rxbuf_size(struct ospf_iface *ifa, u32 rxbuf);
......
......@@ -79,7 +79,6 @@
static int ospf_reload_routes(struct proto *p);
static void ospf_rt_notify(struct proto *p, struct rtable *table UNUSED, net * n, rte * new, rte * old UNUSED, ea_list * attrs);
static void ospf_ifa_notify(struct proto *p, unsigned flags, struct ifa *a);
static int ospf_rte_better(struct rte *new, struct rte *old);
static int ospf_rte_same(struct rte *new, struct rte *old);
static void ospf_disp(timer *timer);
......@@ -196,7 +195,7 @@ ospf_start(struct proto *p)
oa->options = OPT_R | OPT_E | OPT_V6;
#endif
}
ospf_iface_new(po, NULL, ac, ipatt);
ospf_iface_new(po, NULL, NULL, ac, ipatt);
}
}
}
......@@ -503,27 +502,6 @@ ospf_rt_notify(struct proto *p, rtable *tbl UNUSED, net * n, rte * new, rte * ol
flush_ext_lsa(n, po);
}
static void
ospf_ifa_notify(struct proto *p, unsigned flags UNUSED, struct ifa *a)
{
struct proto_ospf *po = (struct proto_ospf *) p;
struct ospf_iface *ifa;
if ((a->flags & IA_SECONDARY) || (a->flags & IA_UNNUMBERED))
return;
WALK_LIST(ifa, po->iface_list)
{
if (ifa->iface == a->iface)
{
schedule_rt_lsa(ifa->oa);
/* Event 5 from RFC5340 4.4.3. */
schedule_link_lsa(ifa);
return;
}
}
}
static void
ospf_get_status(struct proto *p, byte * buf)
{
......@@ -714,12 +692,17 @@ ospf_reconfigure(struct proto *p, struct proto_config *c)
WALK_LIST(ifa, po->iface_list)
{
/* FIXME: better handling of vlinks */
if (ifa->iface == NULL)
continue;
/* FIXME: better matching of interface_id in OSPFv3 */
if (oldip = (struct ospf_iface_patt *)
iface_patt_find(&oldac->patt_list, ifa->iface))
iface_patt_find(&oldac->patt_list, ifa->iface, ifa->addr))
{
/* Now reconfigure interface */
if (!(newip = (struct ospf_iface_patt *)
iface_patt_find(&newac->patt_list, ifa->iface)))
iface_patt_find(&newac->patt_list, ifa->iface, ifa->addr)))
return 0;
/* HELLO TIMER */
......@@ -785,9 +768,7 @@ ospf_reconfigure(struct proto *p, struct proto_config *c)
ifa->stub = newip->stub;
OSPF_TRACE(D_EVENTS, "Interface %s is now stub.", ifa->iface->name);
}
if ((oldip->stub != 0) && (newip->stub == 0) &&
((ifa->ioprob & OSPF_I_IP) == 0) &&
(((ifa->ioprob & OSPF_I_MC) == 0) || (ifa->type == OSPF_IT_NBMA)))
if ((oldip->stub != 0) && (newip->stub == 0) && (ifa->ioprob == OSPF_I_OK))
{
ifa->stub = newip->stub;
OSPF_TRACE(D_EVENTS,
......
......@@ -171,7 +171,8 @@ struct ospf_iface
u32 dead; /* after "deadint" missing hellos is router dead */
u32 vid; /* Id of peer of virtual link */
ip_addr vip; /* IP of peer of virtual link */
struct ospf_area *voa; /* Area wich the vlink goes through */
struct ospf_iface *vifa; /* OSPF iface which the vlink goes through */
struct ospf_area *voa; /* OSPF area which the vlink goes through */
u16 inftransdelay; /* The estimated number of seconds it takes to
transmit a Link State Update Packet over this
interface. LSAs contained in the update */
......@@ -203,9 +204,6 @@ struct ospf_iface
#define OSPF_IT_UNDEF 4
u8 strictnbma; /* Can I talk with unknown neighbors? */
u8 stub; /* Inactive interface */
#define OSPF_I_OK 0 /* Everything OK */
#define OSPF_I_MC 1 /* I didn't open MC socket */
#define OSPF_I_IP 2 /* I didn't open IP socet */
u8 state; /* Interface state machine */
#define OSPF_IS_DOWN 0 /* Not working */
#define OSPF_IS_LOOP 1 /* Should never happen */
......@@ -239,6 +237,9 @@ struct ospf_iface
list nbma_list;
u8 priority; /* A router priority for DR election */
u8 ioprob;
#define OSPF_I_OK 0 /* Everything OK */
#define OSPF_I_SK 1 /* Socket open failed */
#define OSPF_I_LL 2 /* Missing link-local address (OSPFv3) */
u8 sk_spf; /* Socket is a member of SPFRouters group */
u8 sk_dr; /* Socket is a member of DRouters group */
u32 rxbuf;
......
......@@ -424,12 +424,14 @@ ospf_rt_spfa(struct ospf_area *oa)
if ((tmp = ospf_hash_find_rt(po->gr, oa->areaid, iface->vid)) &&
(!ipa_equal(tmp->lb, IPA_NONE)))
{
if ((iface->state != OSPF_IS_PTP) || (iface->iface != tmp->nhi->iface) || (!ipa_equal(iface->vip, tmp->lb)))
if ((iface->state != OSPF_IS_PTP) || (iface->vifa != tmp->nhi) || (!ipa_equal(iface->vip, tmp->lb)))
{
OSPF_TRACE(D_EVENTS, "Vlink peer %R found", tmp->lsa.id);
ospf_iface_sm(iface, ISM_DOWN);
iface->vifa = tmp->nhi;
iface->iface = tmp->nhi->iface;
iface->addr = iface->iface->addr;
iface->addr = tmp->nhi->addr;
iface->sk = tmp->nhi->sk;
iface->vip = tmp->lb;
ospf_iface_sm(iface, ISM_UP);
}
......
......@@ -272,24 +272,20 @@ originate_rt_lsa_body(struct ospf_area *oa, u16 *length)
break;
}
/* Now we will originate stub areas for interfaces addresses */
struct ifa *a;
WALK_LIST(a, ifa->iface->addrs)
{
if (((a == ifa->addr) && net_lsa) ||
(a->flags & IA_SECONDARY) ||
(a->flags & IA_UNNUMBERED) ||
configured_stubnet(oa, a))
continue;
/* Now we will originate stub area if there is no primary */
if (net_lsa ||
(ifa->type == OSPF_IT_VLINK) ||
(ifa->addr->flags & IA_UNNUMBERED) ||
configured_stubnet(oa, ifa->addr))
continue;
ln = lsab_alloc(po, sizeof(struct ospf_lsa_rt_link));
ln->type = LSART_STUB;
ln->id = ipa_to_u32(a->prefix);
ln->data = ipa_to_u32(ipa_mkmask(a->pxlen));
ln->metric = ifa->cost;
ln->padding = 0;
i++;
}
ln = lsab_alloc(po, sizeof(struct ospf_lsa_rt_link));
ln->type = LSART_STUB;
ln->id = ipa_to_u32(ifa->addr->prefix);
ln->data = ipa_to_u32(ipa_mkmask(ifa->addr->pxlen));
ln->metric = ifa->cost;
ln->padding = 0;
i++;
}
struct ospf_stubnet_config *sn;
......@@ -898,6 +894,7 @@ originate_ext_lsa_body(net *n, rte *e, u16 *length, struct proto_ospf *po,
int gw = 0;
int size = sizeof(struct ospf_lsa_ext);
// FIXME check for gw should be per ifa, not per iface
if ((e->attrs->dest == RTD_ROUTER) &&
!ipa_equal(e->attrs->gw, IPA_NONE) &&
!ipa_has_link_scope(e->attrs->gw) &&
......
......@@ -761,7 +761,7 @@ rip_real_if_add(struct object_lock *lock)
struct iface *iface = lock->iface;
struct proto *p = lock->data;
struct rip_interface *rif;
struct iface_patt *k = iface_patt_find(&P_CF->iface_list, iface);
struct iface_patt *k = iface_patt_find(&P_CF->iface_list, iface, iface->addr);
if (!k)
bug("This can not happen! It existed few seconds ago!" );
......@@ -790,7 +790,7 @@ rip_if_notify(struct proto *p, unsigned c, struct iface *iface)
}
}
if (c & IF_CHANGE_UP) {
struct iface_patt *k = iface_patt_find(&P_CF->iface_list, iface);
struct iface_patt *k = iface_patt_find(&P_CF->iface_list, iface, iface->addr);
struct object_lock *lock;
struct rip_patt *PATT = (struct rip_patt *) k;
......
......@@ -62,18 +62,18 @@ get_inaddr(ip_addr *a, struct in_addr *ia)
#define MREQ_IFA struct in_addr
#define MREQ_GRP struct ip_mreq
static inline void fill_mreq_ifa(struct in_addr *m, struct iface *ifa, UNUSED ip_addr maddr)
static inline void fill_mreq_ifa(struct in_addr *m, struct iface *ifa UNUSED, ip_addr saddr, ip_addr maddr UNUSED)
{
set_inaddr(m, ifa->addr->ip);
set_inaddr(m, saddr);
}
static inline void fill_mreq_grp(struct ip_mreq *m, struct iface *ifa, ip_addr maddr)
static inline void fill_mreq_grp(struct ip_mreq *m, struct iface *ifa, ip_addr saddr, ip_addr maddr)
{
bzero(m, sizeof(*m));
#ifdef CONFIG_LINUX_MC_MREQ_BIND
m->imr_interface.s_addr = INADDR_ANY;
#else
set_inaddr(&m->imr_interface, ifa->addr->ip);
set_inaddr(&m->imr_interface, saddr);
#endif
set_inaddr(&m->imr_multiaddr, maddr);
}
......@@ -101,11 +101,11 @@ struct ip_mreqn
#define fill_mreq_ifa fill_mreq
#define fill_mreq_grp fill_mreq
static inline void fill_mreq(struct ip_mreqn *m, struct iface *ifa, ip_addr maddr)
static inline void fill_mreq(struct ip_mreqn *m, struct iface *ifa, ip_addr saddr, ip_addr maddr)
{
bzero(m, sizeof(*m));
m->imr_ifindex = ifa->index;
set_inaddr(&m->imr_address, ifa->addr->ip);
set_inaddr(&m->imr_address, saddr);
set_inaddr(&m->imr_multiaddr, maddr);
}
#endif
......@@ -123,7 +123,7 @@ sysio_setup_multicast(sock *s)
return "IP_MULTICAST_TTL";
/* This defines where should we send _outgoing_ multicasts */
fill_mreq_ifa(&m, s->iface, IPA_NONE);
fill_mreq_ifa(&m, s->iface, s->saddr, IPA_NONE);
if (setsockopt(s->fd, SOL_IP, IP_MULTICAST_IF, &m, sizeof(m)) < 0)
return "IP_MULTICAST_IF";
......@@ -145,7 +145,7 @@ sysio_join_group(sock *s, ip_addr maddr)
MREQ_GRP m;
/* And this one sets interface for _receiving_ multicasts from */
fill_mreq_grp(&m, s->iface, maddr);
fill_mreq_grp(&m, s->iface, s->saddr, maddr);
if (setsockopt(s->fd, SOL_IP, IP_ADD_MEMBERSHIP, &m, sizeof(m)) < 0)
return "IP_ADD_MEMBERSHIP";
......@@ -158,7 +158,7 @@ sysio_leave_group(sock *s, ip_addr maddr)
MREQ_GRP m;
/* And this one sets interface for _receiving_ multicasts from */
fill_mreq_grp(&m, s->iface, maddr);
fill_mreq_grp(&m, s->iface, s->saddr, maddr);
if (setsockopt(s->fd, SOL_IP, IP_DROP_MEMBERSHIP, &m, sizeof(m)) < 0)
return "IP_DROP_MEMBERSHIP";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment