]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: h2: Use BUG_ON() to enforce rules in subscribe/unsubscribe.
authorOlivier Houchard <ohouchard@haproxy.com>
Tue, 14 May 2019 15:50:32 +0000 (17:50 +0200)
committerOlivier Houchard <cognet@ci0.org>
Tue, 14 May 2019 16:18:25 +0000 (18:18 +0200)
It is not legal to subscribe if we're already subscribed, or to unsubscribe
if we did not subscribe, so instead of trying to handle those cases, just
assert that it's ok using the new BUG_ON() macro.

src/mux_h2.c

index 73d32a926b7cd347562da0fd58759162639971e3..90c6a440c6f288b651fba13a337e1a3346fe6209 100644 (file)
@@ -5199,24 +5199,22 @@ static int h2_subscribe(struct conn_stream *cs, int event_type, void *param)
 
        if (event_type & SUB_RETRY_RECV) {
                sw = param;
-               if (!(sw->events & SUB_RETRY_RECV)) {
-                       sw->events |= SUB_RETRY_RECV;
-                       h2s->recv_wait = sw;
-               }
+               BUG_ON(h2s->recv_wait != NULL || (sw->events & SUB_RETRY_RECV));
+               sw->events |= SUB_RETRY_RECV;
+               h2s->recv_wait = sw;
                event_type &= ~SUB_RETRY_RECV;
        }
        if (event_type & SUB_RETRY_SEND) {
                sw = param;
-               if (!(sw->events & SUB_RETRY_SEND)) {
-                       sw->events |= SUB_RETRY_SEND;
-                       h2s->send_wait = sw;
-                       if (!(h2s->flags & H2_SF_BLK_SFCTL) &&
-                           !LIST_ADDED(&h2s->list)) {
-                               if (h2s->flags & H2_SF_BLK_MFCTL)
-                                       LIST_ADDQ(&h2c->fctl_list, &h2s->list);
-                               else
-                                       LIST_ADDQ(&h2c->send_list, &h2s->list);
-                       }
+               BUG_ON(h2s->send_wait != NULL || (sw->events & SUB_RETRY_SEND));
+               sw->events |= SUB_RETRY_SEND;
+               h2s->send_wait = sw;
+               if (!(h2s->flags & H2_SF_BLK_SFCTL) &&
+                   !LIST_ADDED(&h2s->list)) {
+                       if (h2s->flags & H2_SF_BLK_MFCTL)
+                               LIST_ADDQ(&h2c->fctl_list, &h2s->list);
+                       else
+                               LIST_ADDQ(&h2c->send_list, &h2s->list);
                }
                event_type &= ~SUB_RETRY_SEND;
        }
@@ -5237,26 +5235,23 @@ static int h2_unsubscribe(struct conn_stream *cs, int event_type, void *param)
 
        if (event_type & SUB_RETRY_RECV) {
                sw = param;
-               if (h2s->recv_wait == sw) {
-                       sw->events &= ~SUB_RETRY_RECV;
-                       h2s->recv_wait = NULL;
-               }
+               BUG_ON(h2s->recv_wait != sw);
+               sw->events &= ~SUB_RETRY_RECV;
+               h2s->recv_wait = NULL;
        }
        if (event_type & SUB_RETRY_SEND) {
                sw = param;
-               if (h2s->send_wait == sw) {
-                       LIST_DEL(&h2s->list);
-                       LIST_INIT(&h2s->list);
-                       sw->events &= ~SUB_RETRY_SEND;
-                       /* We were about to send, make sure it does not happen */
-                       if (LIST_ADDED(&h2s->sending_list) &&
-                           h2s->send_wait != &h2s->wait_event) {
-                               task_remove_from_tasklet_list((struct task *)h2s->send_wait->task);
-                               LIST_DEL_INIT(&h2s->sending_list);
-                       }
-                       h2s->send_wait = NULL;
-
+               BUG_ON(h2s->send_wait != sw);
+               LIST_DEL(&h2s->list);
+               LIST_INIT(&h2s->list);
+               sw->events &= ~SUB_RETRY_SEND;
+               /* We were about to send, make sure it does not happen */
+               if (LIST_ADDED(&h2s->sending_list) &&
+                   h2s->send_wait != &h2s->wait_event) {
+                       task_remove_from_tasklet_list((struct task *)h2s->send_wait->task);
+                       LIST_DEL_INIT(&h2s->sending_list);
                }
+               h2s->send_wait = NULL;
        }
        return 0;
 }