From 5ed4291f41c8f493f5cf6737e871ca1bf4e7f2a5 Mon Sep 17 00:00:00 2001 From: Dmitry Kozlov Date: Wed, 27 Dec 2017 14:54:00 +0300 Subject: ipoe: include server's mac into weight notify packet to be used as additional key when weights are equal --- accel-pppd/ctrl/ipoe/dhcpv4.c | 3 ++- accel-pppd/ctrl/ipoe/ipoe.c | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/accel-pppd/ctrl/ipoe/dhcpv4.c b/accel-pppd/ctrl/ipoe/dhcpv4.c index 7bbed3f9..dde50603 100644 --- a/accel-pppd/ctrl/ipoe/dhcpv4.c +++ b/accel-pppd/ctrl/ipoe/dhcpv4.c @@ -836,7 +836,7 @@ out_err: void dhcpv4_send_notify(struct dhcpv4_serv *serv, struct dhcpv4_packet *req, unsigned int weight) { struct dhcpv4_packet *pack = dhcpv4_packet_alloc(); - uint8_t opt[8]; + uint8_t opt[8 + ETH_ALEN]; if (!pack) { log_emerg("out of memory\n"); @@ -852,6 +852,7 @@ void dhcpv4_send_notify(struct dhcpv4_serv *serv, struct dhcpv4_packet *req, uns *(uint32_t *)opt = htonl(ACCEL_PPP_MAGIC); *(uint32_t *)(opt + 4) = htonl(weight); + memcpy(opt + 8, serv->hwaddr, ETH_ALEN); dhcpv4_packet_add_opt_u8(pack, 53, DHCPDISCOVER); dhcpv4_packet_add_opt(pack, 43, opt, sizeof(opt)); diff --git a/accel-pppd/ctrl/ipoe/ipoe.c b/accel-pppd/ctrl/ipoe/ipoe.c index 16cc65fd..ed2419fd 100644 --- a/accel-pppd/ctrl/ipoe/ipoe.c +++ b/accel-pppd/ctrl/ipoe/ipoe.c @@ -1685,7 +1685,7 @@ static int check_notify(struct ipoe_serv *serv, struct dhcpv4_packet *pack) if (!opt) return 0; - if (opt->len != 8) + if (opt->len != 8 + ETH_ALEN) return 0; if (*(uint32_t *)opt->data != htonl(ACCEL_PPP_MAGIC)) @@ -1694,8 +1694,8 @@ static int check_notify(struct ipoe_serv *serv, struct dhcpv4_packet *pack) w = htonl(*(uint32_t *)(opt->data + 4)); list_for_each_entry(ses, &serv->sessions, entry) { - if (ses->xid == pack->hdr->xid) { - if (w < ses->weight || ses->weight == 0) { + if (ses->xid == pack->hdr->xid && memcmp(pack->hdr->chaddr, ses->hwaddr, ETH_ALEN) == 0) { + if (w < ses->weight || ses->weight == 0 || (w == ses->weight && memcmp(serv->hwaddr, opt->data + 8, ETH_ALEN) < 0)) { log_debug("ipoe: terminate %s by weight %u (%u)\n", ses->ses.ifname, w, ses->weight); triton_context_call(&ses->ctx, (triton_event_func)__terminate, &ses->ses); } -- cgit v1.2.3