From: Willy Tarreau Date: Tue, 17 May 2022 13:39:33 +0000 (+0200) Subject: MINOR: conn_stream: add new sets of functions to set/get endpoint flags X-Git-Tag: v2.6-dev12~105 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cd1d585e53a7b80b91dc3e0d551ad02c58091b0c;p=thirdparty%2Fhaproxy.git MINOR: conn_stream: add new sets of functions to set/get endpoint flags At plenty of places we need to manipulate the conn_stream's endpoint just to set or clear a flag. This patch adds a handful of functions to perform the common operations (clr/set/get etc) on these flags at both the endpoint and at the conn_stream level. The functions were named after the target names, i.e. se_fl_*() to act on the stream endpoint flags, and sc_ep_* to manipulate the endpoint flags from the stream connector (currently conn_stream). For now they're not used. --- diff --git a/include/haproxy/conn_stream.h b/include/haproxy/conn_stream.h index 1629754823..8e54d58ca4 100644 --- a/include/haproxy/conn_stream.h +++ b/include/haproxy/conn_stream.h @@ -50,6 +50,80 @@ void cs_destroy(struct conn_stream *cs); int cs_reset_endp(struct conn_stream *cs); struct appctx *cs_applet_create(struct conn_stream *cs, struct applet *app); + +/* The se_fl_*() set of functions manipulate the stream endpoint flags from + * the stream endpoint itself. The sc_ep_*() set of functions manipulate the + * stream endpoint flags from the the stream connector (ex. conn_stream). + * _zero() clears all flags, _clr() clears a set of flags (&=~), _set() sets + * a set of flags (|=), _test() tests the presence of a set of flags, _get() + * retrieves the exact flags, _setall() replaces the flags with the new value. + * All functions are purposely marked "forceinline" to avoid slowing down + * debugging code too much. None of these functions is atomic-safe. + */ + +/* stream endpoint version */ +static forceinline void se_fl_zero(struct cs_endpoint *se) +{ + se->flags = 0; +} + +static forceinline void se_fl_setall(struct cs_endpoint *se, uint all) +{ + se->flags = all; +} + +static forceinline void se_fl_set(struct cs_endpoint *se, uint on) +{ + se->flags |= on; +} + +static forceinline void se_fl_clr(struct cs_endpoint *se, uint off) +{ + se->flags &= ~off; +} + +static forceinline uint se_fl_test(const struct cs_endpoint *se, uint test) +{ + return !!(se->flags & test); +} + +static forceinline uint se_fl_get(const struct cs_endpoint *se) +{ + return se->flags; +} + +/* stream connector version */ +static forceinline void sc_ep_zero(struct conn_stream *sc) +{ + se_fl_zero(sc->endp); +} + +static forceinline void sc_ep_setall(struct conn_stream *sc, uint all) +{ + se_fl_setall(sc->endp, all); +} + +static forceinline void sc_ep_set(struct conn_stream *sc, uint on) +{ + se_fl_set(sc->endp, on); +} + +static forceinline void sc_ep_clr(struct conn_stream *sc, uint off) +{ + se_fl_clr(sc->endp, off); +} + +static forceinline uint sc_ep_test(const struct conn_stream *sc, uint test) +{ + return se_fl_test(sc->endp, test); +} + +static forceinline uint sc_ep_get(const struct conn_stream *sc) +{ + return se_fl_get(sc->endp); +} + + /* Returns the endpoint target without any control */ static inline void *__cs_endp_target(const struct conn_stream *cs) {