blob: 993e296bf401a687e541da0b6145da17d0c345c1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
/*
* BIRD Object Locks
*
* (c) 1999 Martin Mares <mj@ucw.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#ifndef _BIRD_LOCKS_H_
#define _BIRD_LOCKS_H_
#include "lib/resource.h"
#include "lib/lists.h"
#include "lib/event.h"
/*
* The object locks are used for controlling exclusive access
* to various physical resources like UDP ports on specific devices.
* When you want to access such resource, you ask for a object lock
* structure, fill in specification of the object and your function
* you want to have called when the object is available and invoke
* olock_acquire() afterwards. When the object becomes free, the lock
* manager calls your function. To free the object lock, just call rfree
* on its resource.
*/
struct object_lock {
resource r;
ip_addr addr; /* Identification of a object: IP address */
uint type; /* ... object type (OBJLOCK_xxx) */
uint port; /* ... port number */
uint inst; /* ... instance ID */
struct iface *iface; /* ... interface */
struct iface *vrf; /* ... or VRF (if iface is unknown) */
event event; /* Enqueued when the lock succeeds */
event_list *target; /* Where to put the event */
/* ... internal to lock manager, don't touch ... */
node n; /* Node in list of olocks */
int state; /* OLOCK_STATE_xxx */
list waiters; /* Locks waiting for the same resource */
};
struct object_lock *olock_new(pool *);
void olock_acquire(struct object_lock *);
void olock_init(void);
#define OBJLOCK_UDP 1 /* UDP port */
#define OBJLOCK_TCP 2 /* TCP port */
#define OBJLOCK_IP 3 /* IP protocol */
#define OLOCK_STATE_FREE 0
#define OLOCK_STATE_LOCKED 1
#define OLOCK_STATE_WAITING 2
#endif
|