From: Alan T. DeKok Date: Mon, 22 Apr 2019 14:35:46 +0000 (-0400) Subject: add thread instance && radclient to packet comparison functions X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a15df8df3f4a60369e1182be5b17002f85c1935c;p=thirdparty%2Ffreeradius-server.git add thread instance && radclient to packet comparison functions most app_io functions should take a thread instance. And, it's good to look at client configuration. this will allow us to do per-connection and per-client negotiation. --- diff --git a/src/lib/io/base.h b/src/lib/io/base.h index 3f7241662cb..abbc787e685 100644 --- a/src/lib/io/base.h +++ b/src/lib/io/base.h @@ -294,6 +294,8 @@ typedef void (*fr_io_data_vnode_t)(fr_listen_t *li, uint32_t fflags); * packets take the same place in any dedup tree. * * @param[in] instance the context for this function + * @param[in] thread_instance the thread instance for this function + * @param[in] client the client associated with this packet * @param[in] packet1 one packet * @param[in] packet2 a second packet * @return @@ -301,7 +303,7 @@ typedef void (*fr_io_data_vnode_t)(fr_listen_t *li, uint32_t fflags); * - >0 on packet two "larger" than packet one * - =0 on the two packets being identical */ -typedef int (*fr_io_data_cmp_t)(void const *instance, void const *packet1, void const *packet2); +typedef int (*fr_io_data_cmp_t)(void const *instance, void *thread_instance, RADCLIENT *client, void const *packet1, void const *packet2); /** Handle an error on the socket. * diff --git a/src/lib/io/master.c b/src/lib/io/master.c index 851c904a9e2..d8e6f9242e1 100644 --- a/src/lib/io/master.c +++ b/src/lib/io/master.c @@ -250,20 +250,22 @@ static int track_cmp(void const *one, void const *two) fr_io_track_t const *b = two; int rcode; - /* - * Call the per-protocol comparison function, if it - * exists. - */ - rcode = a->client->inst->app_io->compare(a->client->inst->app_io_instance, - a->packet, b->packet); - if (rcode != 0) return rcode; - /* * Connected sockets MUST have all tracking entries use * the same client definition. */ if (a->client->connection) { rad_assert(a->client == b->client); + + /* + * Note that we pass the connection "client", as + * we may do negotiation specific to this connection. + */ + rcode = a->client->inst->app_io->compare(a->client->inst->app_io_instance, + a->client->connection->child->thread_instance, + a->client->connection->client->radclient, + a->packet, b->packet); + if (rcode != 0) return rcode; return 0; } @@ -272,7 +274,16 @@ static int track_cmp(void const *one, void const *two) /* * Unconnected sockets must check src/dst ip/port. */ - return address_cmp(a->address, b->address); + rcode = address_cmp(a->address, b->address); + if (rcode != 0) return rcode; + + /* + * Call the per-protocol comparison function. + */ + return a->client->inst->app_io->compare(a->client->inst->app_io_instance, + a->client->thread->child->thread_instance, + a->client->radclient, + a->packet, b->packet); } diff --git a/src/modules/proto_radius/proto_radius_tcp.c b/src/modules/proto_radius/proto_radius_tcp.c index b7370ec3d5a..ebb414905ad 100644 --- a/src/modules/proto_radius/proto_radius_tcp.c +++ b/src/modules/proto_radius/proto_radius_tcp.c @@ -357,7 +357,8 @@ static int mod_fd_set(fr_listen_t *li, int fd) return 0; } -static int mod_compare(UNUSED void const *instance, void const *one, void const *two) +static int mod_compare(UNUSED void const *instance, UNUSED void *thread_instance, UNUSED RADCLIENT *client, + void const *one, void const *two) { int rcode; diff --git a/src/modules/proto_radius/proto_radius_udp.c b/src/modules/proto_radius/proto_radius_udp.c index b0540430715..13c84e4b38f 100644 --- a/src/modules/proto_radius/proto_radius_udp.c +++ b/src/modules/proto_radius/proto_radius_udp.c @@ -396,7 +396,8 @@ static int mod_fd_set(fr_listen_t *li, int fd) return 0; } -static int mod_compare(UNUSED void const *instance, void const *one, void const *two) +static int mod_compare(UNUSED void const *instance, UNUSED void *thread_instance, UNUSED RADCLIENT *client, + void const *one, void const *two) { int rcode; @@ -411,7 +412,7 @@ static int mod_compare(UNUSED void const *instance, void const *one, void const if (rcode != 0) return rcode; /* - * Then ordered by code, which is usally the same. + * Then ordered by code, which is usually the same. */ return (a[0] < b[0]) - (a[0] > b[0]); } diff --git a/src/modules/proto_vmps/proto_vmps_udp.c b/src/modules/proto_vmps/proto_vmps_udp.c index d8312cdf606..2574db3bce0 100644 --- a/src/modules/proto_vmps/proto_vmps_udp.c +++ b/src/modules/proto_vmps/proto_vmps_udp.c @@ -376,7 +376,8 @@ static int mod_fd_set(fr_listen_t *li, int fd) return 0; } -static int mod_compare(UNUSED void const *instance, void const *one, void const *two) +static int mod_compare(UNUSED void const *instance, UNUSED void *thread_instance, UNUSED RADCLIENT *client, + void const *one, void const *two) { int rcode; uint8_t const *a = one;