summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Kozlov <xeb@mail.ru>2017-12-27 14:54:00 +0300
committerDmitry Kozlov <xeb@mail.ru>2017-12-27 14:54:00 +0300
commit5ed4291f41c8f493f5cf6737e871ca1bf4e7f2a5 (patch)
treee192a4c992788f374f3c352e3ca7d02be9bc3d0f
parent1d6f68a518cd7f8cc182080b57d76ed16dc3973a (diff)
downloadaccel-ppp-5ed4291f41c8f493f5cf6737e871ca1bf4e7f2a5.tar.gz
accel-ppp-5ed4291f41c8f493f5cf6737e871ca1bf4e7f2a5.zip
ipoe: include server's mac into weight notify packet to be used as additional key when weights are equal
-rw-r--r--accel-pppd/ctrl/ipoe/dhcpv4.c3
-rw-r--r--accel-pppd/ctrl/ipoe/ipoe.c6
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);
}