diff --git a/include/haproxy/protocol.h b/include/haproxy/protocol.h index 828093d98..a6c50ceb5 100644 --- a/include/haproxy/protocol.h +++ b/include/haproxy/protocol.h @@ -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 */ @@ -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 */ /* diff --git a/src/protocol.c b/src/protocol.c index 69f4595bb..516c020d1 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -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); }