mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 06:11:32 +02:00
MINOR: protocol: add a family lookup
At plenty of places we have access to an address family which may include some custom addresses but we cannot simply convert them to the real families without performing some random protocol lookups. Let's simply add a proto_fam table like we have for the protocols. The protocols could even be indexed there, but for now it's not worth it.
This commit is contained in:
parent
732913f848
commit
ba4a416c66
@ -28,6 +28,7 @@
|
||||
|
||||
/* [AF][sock_dgram][ctrl_dgram] */
|
||||
extern struct protocol *__protocol_by_family[AF_CUST_MAX][PROTO_NUM_TYPES][2];
|
||||
extern const struct proto_fam *__proto_fam_by_family[AF_CUST_MAX];
|
||||
__decl_thread(extern HA_SPINLOCK_T proto_lock);
|
||||
|
||||
/* Registers the protocol <proto> */
|
||||
@ -101,6 +102,17 @@ static inline struct protocol *protocol_lookup(int family, enum proto_type proto
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* returns the proto_fam that matches ss_family. This supports custom address
|
||||
* families so it is suitable for use with ss_family as found in various config
|
||||
* element addresses.
|
||||
*/
|
||||
static inline const struct proto_fam *proto_fam_lookup(int ss_family)
|
||||
{
|
||||
if (ss_family >= 0 && ss_family < AF_CUST_MAX)
|
||||
return __proto_fam_by_family[ss_family];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif /* _HAPROXY_PROTOCOL_H */
|
||||
|
||||
/*
|
||||
|
@ -28,6 +28,7 @@
|
||||
/* List head of all registered protocols */
|
||||
static struct list protocols = LIST_HEAD_INIT(protocols);
|
||||
struct protocol *__protocol_by_family[AF_CUST_MAX][PROTO_NUM_TYPES][2] __read_mostly = { };
|
||||
const struct proto_fam *__proto_fam_by_family[AF_CUST_MAX] = { };
|
||||
|
||||
/* This is the global spinlock we may need to register/unregister listeners or
|
||||
* protocols. Its main purpose is in fact to serialize the rare stop/deinit()
|
||||
@ -48,6 +49,7 @@ void protocol_register(struct protocol *proto)
|
||||
__protocol_by_family[sock_family]
|
||||
[proto->proto_type]
|
||||
[proto->xprt_type == PROTO_TYPE_DGRAM] = proto;
|
||||
__proto_fam_by_family[sock_family] = proto->fam;
|
||||
HA_SPIN_UNLOCK(PROTO_LOCK, &proto_lock);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user