Hi,

please find attached patch for a small bug in relayd that was
introduced with revision 1.126 of relayd.c. The bug makes relayd
forget about the attached table in http rules (i.e. from forward to
<table> options) under certain circumstances. This was observed
in 5.6 and -current on amd64.

The bug becomes visible when more than two tables are defined in the
relay and requests get forwarded to all of them, for example consider
the following (simplified) configuration:

-- snip --

table <table1> { "192.168.1.2" }
table <table2> { "192.168.1.3" }
table <table3> { "192.168.1.4" }

http protocol "http" {

  match request tag "invalid"
  match request path "/path1/*" tag "table1"
  match request path "/path2/*" tag "table2"

  match request tagged "table1" forward to <table1>
  match request tagged "table2" forward to <table2>
  match request tagged "invalid" forward to <table3>

}

relay "relay" {
  listen on * port 80
  protocol "http"
  forward to <table1> port 80
  forward to <table2> port 80
  forward to <table3> port 80
}

-- snap --

Requests tagged "table1" are routed to <table1>, but those tagged with
"table2" are going to the default route (<table1> if up, <table3> when
not) instead of <table2>. This is because rule_settable() in relayd.c
removes the table information from all rules not matching the current
table, except for the last defined table (<table3> in this case).

The following patch might fix that (it did for me). r->rule_table should
already be NULL anyway, because the memory for each rule is
calloc()'ed before by parse.y.

Regards,
Jann

Index: usr.sbin/relayd/relayd.c
===================================================================
RCS file: /cvs/src/usr.sbin/relayd/relayd.c,v
retrieving revision 1.138
diff -u -r1.138 relayd.c
--- usr.sbin/relayd/relayd.c    22 Jan 2015 17:42:09 -0000 1.138
+++ usr.sbin/relayd/relayd.c    15 Mar 2015 16:01:14 -0000
@@ -1020,8 +1020,6 @@
                if (r->rule_tablename[0] &&
                    strcmp(pname, r->rule_tablename) == 0) {
                        r->rule_table = rlt;
-               } else {
-                       r->rule_table = NULL;
                }
        }
 }

--
Be careful who you follow.

Reply via email to