diff options
author | Maria Matejka <mq@ucw.cz> | 2023-01-24 11:01:34 +0100 |
---|---|---|
committer | Maria Matejka <mq@ucw.cz> | 2023-01-26 13:22:28 +0100 |
commit | 05d8c3699d51866c68747167556e7c1f06390afe (patch) | |
tree | f4d02839aa5ad2086779974625e52ba5c2b028d0 /proto | |
parent | 4334f86251429eb39bfe81ff19496d141fccef84 (diff) |
Object locks use events
Instead of calling custom hooks from object locks, we use standard event
sending mechanism to inform protocols about object lock changes. This is
a backport from version 3 where these events are passed across threads.
This implementation of object locks doesn't use mutexes to lock the
whole data structure. In version 3, this data structure may get accessed
from multiple threads and must be protected by mutex.
Diffstat (limited to 'proto')
-rw-r--r-- | proto/babel/babel.c | 10 | ||||
-rw-r--r-- | proto/bgp/bgp.c | 10 | ||||
-rw-r--r-- | proto/ospf/iface.c | 10 | ||||
-rw-r--r-- | proto/radv/radv.c | 10 | ||||
-rw-r--r-- | proto/rip/rip.c | 10 |
5 files changed, 30 insertions, 20 deletions
diff --git a/proto/babel/babel.c b/proto/babel/babel.c index ad7981f6..e1b31e86 100644 --- a/proto/babel/babel.c +++ b/proto/babel/babel.c @@ -1762,9 +1762,9 @@ babel_find_iface(struct babel_proto *p, struct iface *what) } static void -babel_iface_locked(struct object_lock *lock) +babel_iface_locked(void *_ifa) { - struct babel_iface *ifa = lock->data; + struct babel_iface *ifa = _ifa; struct babel_proto *p = ifa->proto; if (!babel_open_socket(ifa)) @@ -1819,8 +1819,10 @@ babel_add_iface(struct babel_proto *p, struct iface *new, struct babel_iface_con lock->addr = IP6_BABEL_ROUTERS; lock->port = ifa->cf->port; lock->iface = ifa->iface; - lock->hook = babel_iface_locked; - lock->data = ifa; + lock->event = (event) { + .hook = babel_iface_locked, + .data = ifa, + }; olock_acquire(lock); } diff --git a/proto/bgp/bgp.c b/proto/bgp/bgp.c index 2e442e16..5b0569ae 100644 --- a/proto/bgp/bgp.c +++ b/proto/bgp/bgp.c @@ -1467,9 +1467,9 @@ bgp_feed_end(struct channel *C) static void -bgp_start_locked(struct object_lock *lock) +bgp_start_locked(void *_p) { - struct bgp_proto *p = lock->data; + struct bgp_proto *p = _p; const struct bgp_config *cf = p->cf; if (p->p.proto_state != PS_START) @@ -1574,8 +1574,10 @@ bgp_start(struct proto *P) lock->iface = p->cf->iface; lock->vrf = p->cf->iface ? NULL : p->p.vrf; lock->type = OBJLOCK_TCP; - lock->hook = bgp_start_locked; - lock->data = p; + lock->event = (event) { + .hook = bgp_start_locked, + .data = p, + }; /* For dynamic BGP, we use inst 1 to avoid collisions with regular BGP */ if (bgp_is_dynamic(p)) diff --git a/proto/ospf/iface.c b/proto/ospf/iface.c index 84c53aa1..c7a6d3d4 100644 --- a/proto/ospf/iface.c +++ b/proto/ospf/iface.c @@ -484,9 +484,9 @@ ospf_iface_find(struct ospf_proto *p, struct iface *what) } static void -ospf_iface_add(struct object_lock *lock) +ospf_iface_add(void *_ifa) { - struct ospf_iface *ifa = lock->data; + struct ospf_iface *ifa = _ifa; struct ospf_proto *p = ifa->oa->po; /* Open socket if interface is not stub */ @@ -668,8 +668,10 @@ ospf_iface_new(struct ospf_area *oa, struct ifa *addr, struct ospf_iface_patt *i lock->port = OSPF_PROTO; lock->inst = ifa->instance_id; lock->iface = iface; - lock->data = ifa; - lock->hook = ospf_iface_add; + lock->event = (event) { + .hook = ospf_iface_add, + .data = ifa, + }; olock_acquire(lock); } diff --git a/proto/radv/radv.c b/proto/radv/radv.c index 8b547f6d..ee1da36c 100644 --- a/proto/radv/radv.c +++ b/proto/radv/radv.c @@ -263,9 +263,9 @@ radv_iface_find(struct radv_proto *p, struct iface *what) } static void -radv_iface_add(struct object_lock *lock) +radv_iface_add(void *_ifa) { - struct radv_iface *ifa = lock->data; + struct radv_iface *ifa = _ifa; struct radv_proto *p = ifa->ra; if (! radv_sk_open(ifa)) @@ -302,8 +302,10 @@ radv_iface_new(struct radv_proto *p, struct iface *iface, struct radv_iface_conf lock->type = OBJLOCK_IP; lock->port = ICMPV6_PROTO; lock->iface = iface; - lock->data = ifa; - lock->hook = radv_iface_add; + lock->event = (event) { + .hook = radv_iface_add, + .data = ifa, + }; ifa->lock = lock; olock_acquire(lock); diff --git a/proto/rip/rip.c b/proto/rip/rip.c index ca218846..93b0d528 100644 --- a/proto/rip/rip.c +++ b/proto/rip/rip.c @@ -656,9 +656,9 @@ rip_iface_update_bfd(struct rip_iface *ifa) static void -rip_iface_locked(struct object_lock *lock) +rip_iface_locked(void *_ifa) { - struct rip_iface *ifa = lock->data; + struct rip_iface *ifa = _ifa; struct rip_proto *p = ifa->rip; if (!rip_open_socket(ifa)) @@ -720,8 +720,10 @@ rip_add_iface(struct rip_proto *p, struct iface *iface, struct rip_iface_config lock->type = OBJLOCK_UDP; lock->port = ic->port; lock->iface = iface; - lock->data = ifa; - lock->hook = rip_iface_locked; + lock->event = (event) { + .hook = rip_iface_locked, + .data = ifa, + }; ifa->lock = lock; olock_acquire(lock); |