Hi, Let's resurrect this question. :) I've made a patch to illustrate what I mean about the wildcard address in the lock object.
Regards, Alexander On Tue, Jan 24, 2023 at 8:22 AM Alexander Zubkov <gr...@qrator.net> wrote: > > > > On Mon, Jan 23, 2023 at 3:17 PM Alexander Zubkov <gr...@qrator.net> wrote: >> >> >> >> On Mon, Jan 23, 2023 at 3:06 PM Ondrej Zajicek <santi...@crfreenet.org> >> wrote: >>> >>> On Mon, Jan 23, 2023 at 12:40:30AM +0100, Alexander Zubkov wrote: >>> > Hi all, >>> > >>> > A quick try to fix the problem. But I'm not sure in complete correctness >>> > though. >>> >>> Hi >>> >>> That looks more-or-less OK, will merge. >>> >>> > - ipa_equal(x->addr, y->addr); >>> > + ipa_equal(x->addr, y->addr) && >>> > + ipa_equal(x->addr2, y->addr2); >>> >>> I think undefined addr2 should work like wildcard, i.e. the condition >>> should be: >>> >> >> Maybe. I do not know well how this lock works. If different lock keys can >> affect another. And in this case it is probably better to fix "local" role >> for that second address and reflect it in its name. > > > I think even better to call this wildcard_addr, for example. So if something > else needs this wildcard feature, it is clear which addr to use in the lock > object. > >> >> >>> >>> ipa_equal(x->addr, y->addr) && >>> (ipa_zero(x->addr2) || ipa_zero(y->addr2) || ipa_equal(x->addr2, >>> y->addr2)); >>> >>> (Undefined local ip will be resolved to some ip and may collide with >>> defined ones.) >>> >>> -- >>> Elen sila lumenn' omentielvo >>> >>> Ondrej 'Santiago' Zajicek (email: santi...@crfreenet.org) >>> OpenPGP encrypted e-mails preferred (KeyID 0x11DEADC3, wwwkeys.pgp.net) >>> "To err is human -- to blame it on a computer is even more so."
diff --git a/nest/locks.c b/nest/locks.c index 812a6534..3d54f0f4 100644 --- a/nest/locks.c +++ b/nest/locks.c @@ -39,6 +39,11 @@ static list olock_list; static event *olock_event; +static inline int ipa_equal_wildcard(ip_addr x, ip_addr y) +{ + return ipa_zero(x) || ipa_zero(y) || ipa_equal(x, y); +} + static inline int olock_same(struct object_lock *x, struct object_lock *y) { @@ -48,7 +53,8 @@ olock_same(struct object_lock *x, struct object_lock *y) x->vrf == y->vrf && x->port == y->port && x->inst == y->inst && - ipa_equal(x->addr, y->addr); + ipa_equal(x->addr_strict, y->addr_strict) && + ipa_equal_wildcard(x->addr_wildcard, y->addr_wildcard); } static void @@ -91,7 +97,7 @@ olock_dump(resource *r) struct object_lock *l = (struct object_lock *) r; static char *olock_states[] = { "free", "locked", "waiting", "event" }; - debug("(%d:%s:%I:%d:%d) [%s]\n", l->type, (l->iface ? l->iface->name : "?"), l->addr, l->port, l->inst, olock_states[l->state]); + debug("(%d:%s:%I:%I:%d:%d) [%s]\n", l->type, (l->iface ? l->iface->name : "?"), l->addr_strict, l->addr_wildcard, l->port, l->inst, olock_states[l->state]); if (!EMPTY_LIST(l->waiters)) debug(" [wanted]\n"); } diff --git a/nest/locks.h b/nest/locks.h index 37026c68..e68321ae 100644 --- a/nest/locks.h +++ b/nest/locks.h @@ -25,7 +25,8 @@ struct object_lock { resource r; - ip_addr addr; /* Identification of a object: IP address */ + ip_addr addr_strict; /* Identification of a object: IP address (strict compare) */ + ip_addr addr_wildcard; /* ... another IP address (allow zero IP wildcard) */ uint type; /* ... object type (OBJLOCK_xxx) */ uint port; /* ... port number */ uint inst; /* ... instance ID */ diff --git a/proto/babel/babel.c b/proto/babel/babel.c index 4187d258..113781d4 100644 --- a/proto/babel/babel.c +++ b/proto/babel/babel.c @@ -1932,7 +1932,7 @@ babel_add_iface(struct babel_proto *p, struct iface *new, struct babel_iface_con struct object_lock *lock = olock_new(ifa->pool); lock->type = OBJLOCK_UDP; - lock->addr = IP6_BABEL_ROUTERS; + lock->addr_strict = IP6_BABEL_ROUTERS; lock->port = ifa->cf->port; lock->iface = ifa->iface; lock->hook = babel_iface_locked; diff --git a/proto/bgp/bgp.c b/proto/bgp/bgp.c index 9d4671af..33e869d4 100644 --- a/proto/bgp/bgp.c +++ b/proto/bgp/bgp.c @@ -1615,7 +1615,8 @@ bgp_start(struct proto *P) */ struct object_lock *lock; lock = p->lock = olock_new(P->pool); - lock->addr = p->remote_ip; + lock->addr_strict = p->remote_ip; + lock->addr_wildcard = p->cf->local_ip; lock->port = p->cf->remote_port; lock->iface = p->cf->iface; lock->vrf = p->cf->iface ? NULL : p->p.vrf; @@ -1626,7 +1627,7 @@ bgp_start(struct proto *P) /* For dynamic BGP, we use inst 1 to avoid collisions with regular BGP */ if (bgp_is_dynamic(p)) { - lock->addr = net_prefix(p->cf->remote_range); + lock->addr_strict = net_prefix(p->cf->remote_range); lock->inst = 1; } diff --git a/proto/ospf/iface.c b/proto/ospf/iface.c index dd922b00..cf26cf28 100644 --- a/proto/ospf/iface.c +++ b/proto/ospf/iface.c @@ -663,7 +663,7 @@ ospf_iface_new(struct ospf_area *oa, struct ifa *addr, struct ospf_iface_patt *i add_tail(&oa->po->iface_list, NODE ifa); struct object_lock *lock = olock_new(pool); - lock->addr = ospf_is_v2(p) ? ipa_from_ip4(net4_prefix(&ifa->addr->prefix)) : IPA_NONE; + lock->addr_strict = ospf_is_v2(p) ? ipa_from_ip4(net4_prefix(&ifa->addr->prefix)) : IPA_NONE; lock->type = OBJLOCK_IP; lock->port = OSPF_PROTO; lock->inst = ifa->instance_id;