summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKozlov Dmitry <xeb@mail.ru>2013-01-28 17:33:16 +0400
committerKozlov Dmitry <xeb@mail.ru>2013-01-28 17:33:16 +0400
commitb604b6d912f100403def472d4a9a165612e439b2 (patch)
tree3b5ad3dd0d548c3265de48377d502fb4f5d182b2
parent0ca38d8e1246716c8b53bc3191c5cccf9f228251 (diff)
downloadaccel-ppp-b604b6d912f100403def472d4a9a165612e439b2.tar.gz
accel-ppp-b604b6d912f100403def472d4a9a165612e439b2.zip
ipoe: changed assignment of Server-ID and Router options
-rw-r--r--accel-pppd/ctrl/ipoe/dhcpv4.c6
-rw-r--r--accel-pppd/ctrl/ipoe/dhcpv4.h2
-rw-r--r--accel-pppd/ctrl/ipoe/ipoe.c49
-rw-r--r--accel-pppd/ctrl/ipoe/ipoe.h1
4 files changed, 34 insertions, 24 deletions
diff --git a/accel-pppd/ctrl/ipoe/dhcpv4.c b/accel-pppd/ctrl/ipoe/dhcpv4.c
index e5a8731..5885ac4 100644
--- a/accel-pppd/ctrl/ipoe/dhcpv4.c
+++ b/accel-pppd/ctrl/ipoe/dhcpv4.c
@@ -661,7 +661,7 @@ int dhcpv4_packet_add_opt(struct dhcpv4_packet *pack, int type, const void *data
return 0;
}
-int dhcpv4_send_reply(int msg_type, struct dhcpv4_serv *serv, struct dhcpv4_packet *req, uint32_t yiaddr, uint32_t siaddr, uint32_t mask, int lease_time, struct dhcpv4_packet *relay)
+int dhcpv4_send_reply(int msg_type, struct dhcpv4_serv *serv, struct dhcpv4_packet *req, uint32_t yiaddr, uint32_t siaddr, uint32_t router, uint32_t mask, int lease_time, struct dhcpv4_packet *relay)
{
struct dhcpv4_packet *pack;
int val, r;
@@ -698,7 +698,7 @@ int dhcpv4_send_reply(int msg_type, struct dhcpv4_serv *serv, struct dhcpv4_pack
if (dhcpv4_packet_add_opt(pack, 51, &val, 4))
goto out_err;
- if (dhcpv4_packet_add_opt(pack, 3, &siaddr, 4))
+ if (router && dhcpv4_packet_add_opt(pack, 3, &router, 4))
goto out_err;
val = htonl(~((1 << (32 - mask)) - 1));
@@ -707,7 +707,7 @@ int dhcpv4_send_reply(int msg_type, struct dhcpv4_serv *serv, struct dhcpv4_pack
if (relay) {
list_for_each_entry(opt, &relay->options, entry) {
- if (opt->type == 53 || opt->type == 54 || opt->type == 51 || opt->type == 3 || opt->type == 1)
+ if (opt->type == 53 || opt->type == 54 || opt->type == 51 || opt->type == 1 || (opt->type == 3 && router))
continue;
if (opt->type == 6)
dns_avail = 1;
diff --git a/accel-pppd/ctrl/ipoe/dhcpv4.h b/accel-pppd/ctrl/ipoe/dhcpv4.h
index cea0934..b7602e1 100644
--- a/accel-pppd/ctrl/ipoe/dhcpv4.h
+++ b/accel-pppd/ctrl/ipoe/dhcpv4.h
@@ -111,7 +111,7 @@ int dhcpv4_relay_send_release(struct dhcpv4_relay *relay, uint8_t *chaddr, uint3
struct dhcpv4_option *client_id, struct dhcpv4_option *relay_agent,
const char *agent_circuit_id, const char *agent_remote_id);
-int dhcpv4_send_reply(int msg_type, struct dhcpv4_serv *serv, struct dhcpv4_packet *req, uint32_t yiaddr, uint32_t siaddr, uint32_t mask, int lease_time, struct dhcpv4_packet *relay_reply);
+int dhcpv4_send_reply(int msg_type, struct dhcpv4_serv *serv, struct dhcpv4_packet *req, uint32_t yiaddr, uint32_t siaddr, uint32_t router, uint32_t mask, int lease_time, struct dhcpv4_packet *relay_reply);
int dhcpv4_send_nak(struct dhcpv4_serv *serv, struct dhcpv4_packet *req);
void dhcpv4_packet_ref(struct dhcpv4_packet *pack);
diff --git a/accel-pppd/ctrl/ipoe/ipoe.c b/accel-pppd/ctrl/ipoe/ipoe.c
index b2ae708..223594e 100644
--- a/accel-pppd/ctrl/ipoe/ipoe.c
+++ b/accel-pppd/ctrl/ipoe/ipoe.c
@@ -413,7 +413,7 @@ static void ipoe_session_start(struct ipoe_session *ses)
static void __ipoe_session_start(struct ipoe_session *ses)
{
if (!ses->yiaddr) {
- dhcpv4_get_ip(ses->serv->dhcpv4, &ses->yiaddr, &ses->siaddr, &ses->mask);
+ dhcpv4_get_ip(ses->serv->dhcpv4, &ses->yiaddr, &ses->router, &ses->mask);
if (ses->yiaddr)
ses->dhcp_addr = 1;
}
@@ -436,9 +436,9 @@ static void __ipoe_session_start(struct ipoe_session *ses)
if (!ses->yiaddr)
ses->yiaddr = ses->ses.ipv4->peer_addr;
-
- if (!ses->siaddr)
- ses->siaddr = ses->ses.ipv4->addr;
+
+ if (!ses->router)
+ ses->router = ses->ses.ipv4->addr;
} else if (ses->yiaddr) {
ses->ses.ipv4 = &ses->ipv4;
ses->ipv4.addr = ses->siaddr;
@@ -446,12 +446,30 @@ static void __ipoe_session_start(struct ipoe_session *ses)
ses->ipv4.mask = ses->mask;
ses->ipv4.owner = NULL;
}
+
+ if (!ses->yiaddr) {
+ log_ppp_error("no free IPv4 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 && ses->serv->dhcpv4_relay)
+ ses->siaddr = ses->serv->dhcpv4_relay->giaddr;
+
+ if (!ses->siaddr) {
+ log_ppp_error("can't determine Server-ID\n");
+ ap_session_terminate(&ses->ses, TERM_NAS_ERROR, 0);
+ return;
+ }
+
if (!ses->mask)
- ses->mask = 24;
+ ses->mask = 32;
if (ses->dhcpv4_request) {
- dhcpv4_send_reply(DHCPOFFER, ses->serv->dhcpv4, ses->dhcpv4_request, ses->yiaddr, ses->siaddr, ses->mask, ses->lease_time, ses->dhcpv4_relay_reply);
+ 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);
ses->dhcpv4_request = NULL;
@@ -587,7 +605,7 @@ static void __ipoe_session_activate(struct ipoe_session *ses)
if (ses->dhcpv4_request) {
if (ses->ses.state == AP_STATE_ACTIVE)
- dhcpv4_send_reply(DHCPACK, ses->serv->dhcpv4, ses->dhcpv4_request, ses->yiaddr, ses->siaddr, ses->mask, ses->lease_time, ses->dhcpv4_relay_reply);
+ dhcpv4_send_reply(DHCPACK, ses->serv->dhcpv4, ses->dhcpv4_request, ses->yiaddr, ses->siaddr, ses->router, ses->mask, ses->lease_time, ses->dhcpv4_relay_reply);
else
dhcpv4_send_nak(ses->serv->dhcpv4, ses->dhcpv4_request);
@@ -629,7 +647,7 @@ static void ipoe_session_keepalive(struct dhcpv4_packet *pack)
}
if (ses->ses.state == AP_STATE_ACTIVE) {
- dhcpv4_send_reply(DHCPACK, ses->serv->dhcpv4, ses->dhcpv4_request, ses->yiaddr, ses->siaddr, ses->mask, ses->lease_time, ses->dhcpv4_relay_reply);
+ dhcpv4_send_reply(DHCPACK, ses->serv->dhcpv4, ses->dhcpv4_request, ses->yiaddr, ses->siaddr, ses->router, ses->mask, ses->lease_time, ses->dhcpv4_relay_reply);
} else
dhcpv4_send_nak(ses->serv->dhcpv4, ses->dhcpv4_request);
@@ -874,7 +892,7 @@ static void ipoe_recv_dhcpv4(struct dhcpv4_serv *dhcpv4, struct dhcpv4_packet *p
}
if (ses->ses.state == AP_STATE_ACTIVE && pack->request_ip == ses->yiaddr)
- dhcpv4_send_reply(DHCPOFFER, dhcpv4, pack, ses->yiaddr, ses->siaddr, ses->mask, ses->lease_time, ses->dhcpv4_relay_reply);
+ dhcpv4_send_reply(DHCPOFFER, dhcpv4, pack, ses->yiaddr, ses->siaddr, ses->router, ses->mask, ses->lease_time, ses->dhcpv4_relay_reply);
}
} else if (pack->msg_type == DHCPREQUEST) {
ses = ipoe_session_lookup(serv, pack);
@@ -963,15 +981,6 @@ static void ipoe_ses_recv_dhcpv4_relay(struct ipoe_session *ses)
ses->relay_addr = 1;
}
- if (!ses->siaddr) {
- opt = dhcpv4_packet_find_opt(pack, 3);
- if (opt)
- ses->siaddr = *(in_addr_t *)opt->data;
- }
-
- if ((!ses->siaddr || ses->siaddr == ses->yiaddr) && ses->serv->dhcpv4_relay)
- ses->siaddr = ses->serv->dhcpv4_relay->giaddr;
-
opt = dhcpv4_packet_find_opt(pack, 51);
if (opt)
ses->lease_time = ntohl(*(uint32_t *)opt->data);
@@ -985,7 +994,7 @@ static void ipoe_ses_recv_dhcpv4_relay(struct ipoe_session *ses)
if (ses->ses.state == AP_STATE_STARTING)
__ipoe_session_activate(ses);
else
- dhcpv4_send_reply(DHCPACK, ses->serv->dhcpv4, ses->dhcpv4_request, ses->yiaddr, ses->siaddr, ses->mask, ses->lease_time, ses->dhcpv4_relay_reply);
+ dhcpv4_send_reply(DHCPACK, ses->serv->dhcpv4, ses->dhcpv4_request, ses->yiaddr, ses->siaddr, ses->router, ses->mask, ses->lease_time, ses->dhcpv4_relay_reply);
} else if (pack->msg_type == DHCPNAK) {
dhcpv4_send_nak(ses->serv->dhcpv4, ses->dhcpv4_request);
@@ -1161,7 +1170,7 @@ static void ev_radius_access_accept(struct ev_radius_t *ev)
if (attr->attr->id == conf_attr_dhcp_client_ip)
ses->yiaddr = attr->val.ipaddr;
else if (attr->attr->id == conf_attr_dhcp_router_ip)
- ses->siaddr = attr->val.ipaddr;
+ ses->router = attr->val.ipaddr;
else if (attr->attr->id == conf_attr_dhcp_mask) {
if (attr->val.integer > 0 && attr->val.integer < 31)
ses->mask = attr->val.integer;
diff --git a/accel-pppd/ctrl/ipoe/ipoe.h b/accel-pppd/ctrl/ipoe/ipoe.h
index 8c889ec..085aeda 100644
--- a/accel-pppd/ctrl/ipoe/ipoe.h
+++ b/accel-pppd/ctrl/ipoe/ipoe.h
@@ -46,6 +46,7 @@ struct ipoe_session
uint32_t giaddr;
uint32_t yiaddr;
uint32_t siaddr;
+ uint32_t router;
uint32_t relay_server_id;
int mask;
int lease_time;