summaryrefslogtreecommitdiff
path: root/accel-pppd/ctrl
diff options
context:
space:
mode:
Diffstat (limited to 'accel-pppd/ctrl')
-rw-r--r--accel-pppd/ctrl/ipoe/dhcpv4.c38
-rw-r--r--accel-pppd/ctrl/ipoe/dhcpv4.h1
-rw-r--r--accel-pppd/ctrl/ipoe/ipoe.c67
3 files changed, 70 insertions, 36 deletions
diff --git a/accel-pppd/ctrl/ipoe/dhcpv4.c b/accel-pppd/ctrl/ipoe/dhcpv4.c
index b34a239..936b50e 100644
--- a/accel-pppd/ctrl/ipoe/dhcpv4.c
+++ b/accel-pppd/ctrl/ipoe/dhcpv4.c
@@ -506,6 +506,8 @@ static int dhcpv4_read(struct triton_md_handler_t *h)
continue;
}
+ pack->src_addr = addr.sin_addr.s_addr;
+
if (serv->recv)
serv->recv(serv, pack);
@@ -640,7 +642,7 @@ static int dhcpv4_send_raw(struct dhcpv4_serv *serv, struct dhcpv4_packet *pack,
return 0;
}
-static int dhcpv4_send_udp(struct dhcpv4_serv *serv, struct dhcpv4_packet *pack)
+static int dhcpv4_send_udp(struct dhcpv4_serv *serv, struct dhcpv4_packet *pack, in_addr_t ip, int port)
{
struct sockaddr_in addr;
int n;
@@ -648,8 +650,8 @@ static int dhcpv4_send_udp(struct dhcpv4_serv *serv, struct dhcpv4_packet *pack)
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
- addr.sin_port = htons(DHCP_CLIENT_PORT);
- addr.sin_addr.s_addr = pack->hdr->giaddr;
+ addr.sin_port = htons(port);
+ addr.sin_addr.s_addr = ip;
n = sendto(serv->hnd.fd, pack->data, len, 0, (struct sockaddr *)&addr, sizeof(addr));
if (n != len)
@@ -658,14 +660,6 @@ static int dhcpv4_send_udp(struct dhcpv4_serv *serv, struct dhcpv4_packet *pack)
return 0;
}
-static int dhcpv4_send(struct dhcpv4_serv *serv, struct dhcpv4_packet *pack, in_addr_t saddr, in_addr_t daddr)
-{
- if (pack->hdr->giaddr)
- return dhcpv4_send_udp(serv, pack);
-
- return dhcpv4_send_raw(serv, pack, saddr, daddr);
-}
-
int dhcpv4_packet_add_opt(struct dhcpv4_packet *pack, int type, const void *data, int len)
{
struct dhcpv4_option *opt = mempool_alloc(opt_pool);
@@ -713,12 +707,13 @@ int dhcpv4_send_reply(int msg_type, struct dhcpv4_serv *serv, struct dhcpv4_pack
memcpy(pack->hdr, req->hdr, sizeof(*req->hdr));
pack->hdr->op = DHCP_OP_REPLY;
- //pack->hdr->ciaddr = 0;
pack->hdr->yiaddr = yiaddr;
- if (msg_type == DHCPOFFER)
- pack->hdr->siaddr = siaddr;
+ if (msg_type == DHCPACK)
+ pack->hdr->ciaddr = req->hdr->ciaddr;
else
- pack->hdr->siaddr = 0;
+ pack->hdr->ciaddr = 0;
+ pack->hdr->siaddr = 0;
+ pack->hdr->giaddr = req->hdr->giaddr;
if (dhcpv4_packet_add_opt(pack, 53, &msg_type, 1))
goto out_err;
@@ -768,7 +763,12 @@ int dhcpv4_send_reply(int msg_type, struct dhcpv4_serv *serv, struct dhcpv4_pack
dhcpv4_print_packet(pack, 0, log_ppp_info2);
}
- r = dhcpv4_send(serv, pack, siaddr, yiaddr);
+ if (req->hdr->giaddr)
+ r = dhcpv4_send_udp(serv, pack, req->hdr->giaddr, DHCP_SERV_PORT);
+ else if (pack->hdr->ciaddr)
+ r = dhcpv4_send_udp(serv, pack, req->hdr->ciaddr, DHCP_CLIENT_PORT);
+ else
+ r = dhcpv4_send_raw(serv, pack, siaddr, yiaddr);
dhcpv4_packet_free(pack);
@@ -796,6 +796,7 @@ int dhcpv4_send_nak(struct dhcpv4_serv *serv, struct dhcpv4_packet *req)
pack->hdr->ciaddr = 0;
pack->hdr->yiaddr = 0;
pack->hdr->siaddr = 0;
+ pack->hdr->giaddr = req->hdr->giaddr;
val = DHCPNAK;
if (dhcpv4_packet_add_opt(pack, 53, &val, 1))
@@ -809,7 +810,10 @@ int dhcpv4_send_nak(struct dhcpv4_serv *serv, struct dhcpv4_packet *req)
dhcpv4_print_packet(pack, 0, log_info2);
}
- r = dhcpv4_send(serv, pack, 0, 0xffffffff);
+ if (req->hdr->giaddr)
+ r = dhcpv4_send_udp(serv, pack, req->hdr->giaddr, DHCP_SERV_PORT);
+ else
+ r = dhcpv4_send_raw(serv, pack, 0, 0xffffffff);
dhcpv4_packet_free(pack);
diff --git a/accel-pppd/ctrl/ipoe/dhcpv4.h b/accel-pppd/ctrl/ipoe/dhcpv4.h
index 7494b73..15db8ed 100644
--- a/accel-pppd/ctrl/ipoe/dhcpv4.h
+++ b/accel-pppd/ctrl/ipoe/dhcpv4.h
@@ -65,6 +65,7 @@ struct dhcpv4_packet {
uint32_t request_ip;
uint32_t server_id;
int msg_type;
+ in_addr_t src_addr;
int volatile refs;
uint8_t *ptr;
uint8_t data[0];
diff --git a/accel-pppd/ctrl/ipoe/ipoe.c b/accel-pppd/ctrl/ipoe/ipoe.c
index ac26b41..87aa897 100644
--- a/accel-pppd/ctrl/ipoe/ipoe.c
+++ b/accel-pppd/ctrl/ipoe/ipoe.c
@@ -615,7 +615,7 @@ static void find_gw_addr(struct ipoe_session *ses)
list_for_each_entry(a, &conf_gw_addr, entry) {
if ((ntohl(ses->yiaddr) & (a->mask1)) == (ntohl(a->addr) & (a->mask1))) {
- ses->siaddr = a->addr;
+ ses->router = a->addr;
ses->mask = a->mask;
return;
}
@@ -633,9 +633,6 @@ static void __ipoe_session_start(struct ipoe_session *ses)
if (!ses->yiaddr && !ses->serv->opt_nat)
ses->ses.ipv4 = ipdb_get_ipv4(&ses->ses);
- if (!ses->mask)
- ses->mask = conf_netmask;
-
if (ses->ses.ipv4) {
if (!ses->mask)
ses->mask = ses->ses.ipv4->mask;
@@ -652,21 +649,50 @@ static void __ipoe_session_start(struct ipoe_session *ses)
ses->ipv4.mask = ses->mask;
ses->ipv4.owner = NULL;
}*/
-
+
if (ses->dhcpv4_request) {
if (!ses->yiaddr) {
log_ppp_error("no free IPv4 address\n");
ap_session_terminate(&ses->ses, TERM_NAS_REQUEST, 0);
return;
}
+
+ if (!ses->router)
+ find_gw_addr(ses);
+
+ if (!ses->mask)
+ ses->mask = conf_netmask;
+
+ if (!ses->mask)
+ ses->mask = 32;
+
+ if (ses->dhcpv4_request->hdr->giaddr) {
+ /*uint32_t mask = ses->mask == 32 ? 0xffffffff : (((1 << ses->mask) - 1) << (32 - ses->mask));
+
+ ses->siaddr = iproute_get(ses->dhcpv4_request->hdr->giaddr);
+ if ((ntohl(ses->router) & mask) == (ntohl(ses->siaddr) & mask))
+ ses->siaddr = ses->router;
+ else if (!ses->router)
+ ses->router = ses->dhcpv4_request->hdr->giaddr;*/
+ if (ses->serv->opt_mode == MODE_L2)
+ ses->siaddr = ses->router;
+ else {
+ ses->siaddr = iproute_get(ses->dhcpv4_request->hdr->giaddr, NULL);
+ if (!ses->router)
+ ses->router = ses->dhcpv4_request->hdr->giaddr;
+ }
+ }
+
+ if (!ses->router) {
+ log_ppp_error("can't determine router address\n");
+ ap_session_terminate(&ses->ses, TERM_NAS_REQUEST, 0);
+ return;
+ }
if (!ses->siaddr && ses->router != ses->yiaddr)
ses->siaddr = ses->router;
if (!ses->siaddr)
- find_gw_addr(ses);
-
- if (!ses->siaddr)
ses->siaddr = ses->serv->opt_src;
if (!ses->siaddr && ses->serv->dhcpv4_relay)
@@ -681,12 +707,6 @@ static void __ipoe_session_start(struct ipoe_session *ses)
if (ses->ses.ipv4 && !ses->ses.ipv4->addr)
ses->ses.ipv4->addr = ses->siaddr;
- if (!ses->router)
- ses->router = ses->siaddr;
-
- if (!ses->mask)
- ses->mask = 32;
-
dhcpv4_send_reply(DHCPOFFER, ses->serv->dhcpv4, ses->dhcpv4_request, ses->yiaddr, ses->siaddr, ses->router, ses->mask, ses->lease_time, ses->dhcpv4_relay_reply);
dhcpv4_packet_free(ses->dhcpv4_request);
@@ -704,7 +724,7 @@ static void __ipoe_session_start(struct ipoe_session *ses)
ses->siaddr = ses->serv->opt_src;
if (!ses->siaddr)
- ses->siaddr = iproute_get(ses->yiaddr);
+ ses->siaddr = iproute_get(ses->yiaddr, NULL);
if (!ses->siaddr) {
log_ppp_error("can't determine local address\n");
@@ -779,7 +799,7 @@ static void ipoe_ifcfg_add(struct ipoe_session *ses)
ipoe_serv_add_addr(ses->serv, ses->siaddr, conf_ip_unnumbered ? 32 : ses->mask);
if (conf_ip_unnumbered) {
- if (iproute_add(serv->ifindex, ses->serv->opt_src ? ses->serv->opt_src : ses->router, ses->yiaddr, conf_proto))
+ if (iproute_add(serv->ifindex, ses->serv->opt_src ? ses->serv->opt_src : ses->router, ses->yiaddr, 0, conf_proto))
log_ppp_warn("ipoe: failed to add route to interface '%s'\n", serv->ifname);
}
@@ -817,7 +837,16 @@ static void __ipoe_session_activate(struct ipoe_session *ses)
addr = ses->ses.ipv4->peer_addr;
else if (!conf_ip_unnumbered)
ses->ctrl.dont_ifcfg = 1;
-
+
+ if (ses->dhcpv4_request && ses->serv->opt_mode == MODE_L3) {
+ in_addr_t gw;
+ iproute_get(ses->router, &gw);
+ if (gw)
+ iproute_add(0, ses->siaddr, ses->yiaddr, gw, conf_proto);
+ else
+ iproute_add(0, ses->siaddr, ses->router, gw, conf_proto);
+ }
+
if (ipoe_nl_modify(ses->ifindex, ses->yiaddr, addr, NULL, NULL)) {
ap_session_terminate(&ses->ses, TERM_NAS_ERROR, 0);
return;
@@ -837,10 +866,10 @@ static void __ipoe_session_activate(struct ipoe_session *ses)
ipoe_nl_add_exclude(ses->yiaddr, 32);
- iproute_add(ses->serv->ifindex, ses->siaddr, ses->yiaddr, conf_proto);
+ iproute_add(ses->serv->ifindex, ses->siaddr, ses->yiaddr, 0, conf_proto);
ses->ctrl.dont_ifcfg = 1;
- } else if (ses->ctrl.dont_ifcfg)
+ } else if (ses->ctrl.dont_ifcfg && ses->serv->opt_mode == MODE_L2)
ipaddr_add(ses->ifindex, ses->siaddr, ses->mask);
if (ses->l4_redirect)