diff options
author | Dmitry Kozlov <xeb@mail.ru> | 2015-11-17 23:05:11 +0300 |
---|---|---|
committer | Dmitry Kozlov <xeb@mail.ru> | 2015-11-17 23:05:11 +0300 |
commit | 74c00bfc521a6136d4ee0d776f8d1717014b2bfc (patch) | |
tree | 3961e354f67fdf37ceed303fa9d2ab4dec4a3df2 /accel-pppd | |
parent | b498b81ebc4eee1f75ff1ef87d65d8f223c31ba6 (diff) | |
download | accel-ppp-74c00bfc521a6136d4ee0d776f8d1717014b2bfc.tar.gz accel-ppp-74c00bfc521a6136d4ee0d776f8d1717014b2bfc.zip |
ipoe: implemented dhcp option 58
Diffstat (limited to 'accel-pppd')
-rw-r--r-- | accel-pppd/accel-ppp.conf | 1 | ||||
-rw-r--r-- | accel-pppd/accel-ppp.conf.5 | 3 | ||||
-rw-r--r-- | accel-pppd/ctrl/ipoe/backup.c | 5 | ||||
-rw-r--r-- | accel-pppd/ctrl/ipoe/dhcpv4.c | 10 | ||||
-rw-r--r-- | accel-pppd/ctrl/ipoe/dhcpv4.h | 2 | ||||
-rw-r--r-- | accel-pppd/ctrl/ipoe/ipoe.c | 32 | ||||
-rw-r--r-- | accel-pppd/ctrl/ipoe/ipoe.h | 1 |
7 files changed, 44 insertions, 10 deletions
diff --git a/accel-pppd/accel-ppp.conf b/accel-pppd/accel-ppp.conf index 328831bc..81d176d6 100644 --- a/accel-pppd/accel-ppp.conf +++ b/accel-pppd/accel-ppp.conf @@ -102,6 +102,7 @@ verbose=1 username=ifname #password=username lease-time=600 +renew-time=600 max-lease-time=3600 #unit-cache=1000 #l4-redirect-table=4 diff --git a/accel-pppd/accel-ppp.conf.5 b/accel-pppd/accel-ppp.conf.5 index bb6dd4d8..8923b06f 100644 --- a/accel-pppd/accel-ppp.conf.5 +++ b/accel-pppd/accel-ppp.conf.5 @@ -234,6 +234,9 @@ Or you can specify fixed password in .BI "lease-time=" n Specifies lease time in seconds to be sent to dhcp client. .TP +.BI "renew-time=" n +Specifies lease renew time (option 58) in seconds to be sent to dhcp client. +.TP .BI "max-lease-time=" n Specifies max lease time in seconds, after this time session will be terminated if client won't renew it. .TP diff --git a/accel-pppd/ctrl/ipoe/backup.c b/accel-pppd/ctrl/ipoe/backup.c index b272731b..4e728555 100644 --- a/accel-pppd/ctrl/ipoe/backup.c +++ b/accel-pppd/ctrl/ipoe/backup.c @@ -27,6 +27,7 @@ #define IPOE_TAG_MASK 13 #define IPOE_TAG_RELAY_SERVER_ID 14 #define IPOE_TAG_LEASE_TIME 15 +#define IPOE_TAG_RENEW_TIME 16 #define IPOE_TAG_IFINDEX 100 @@ -75,6 +76,7 @@ static int session_save(struct ap_session *ses, struct backup_mod *m) add_tag(IPOE_TAG_FLAGS, &flags, 4); add_tag(IPOE_TAG_RELAY_SERVER_ID, &conn->relay_server_id, 4); add_tag(IPOE_TAG_LEASE_TIME, &conn->lease_time, 4); + add_tag(IPOE_TAG_RENEW_TIME, &conn->renew_time, 4); add_tag(IPOE_TAG_IFNAME, conn->serv->ifname, strlen(conn->serv->ifname) + 1); if (conn->client_id) @@ -195,6 +197,9 @@ static struct ap_session *ctrl_restore(struct backup_mod *m) case IPOE_TAG_LEASE_TIME: ses->lease_time = *(uint32_t *)t->data; break; + case IPOE_TAG_RENEW_TIME: + ses->renew_time = *(uint32_t *)t->data; + break; } } diff --git a/accel-pppd/ctrl/ipoe/dhcpv4.c b/accel-pppd/ctrl/ipoe/dhcpv4.c index f58a49a7..94d39175 100644 --- a/accel-pppd/ctrl/ipoe/dhcpv4.c +++ b/accel-pppd/ctrl/ipoe/dhcpv4.c @@ -692,7 +692,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 router, 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, int renew_time, struct dhcpv4_packet *relay) { struct dhcpv4_packet *pack; int val, r; @@ -730,6 +730,12 @@ 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; + val = ntohl(renew_time); + if (val > 0){ + if (dhcpv4_packet_add_opt(pack, 58, &val, 4)) + goto out_err; + } + if (router && dhcpv4_packet_add_opt(pack, 3, &router, 4)) goto out_err; @@ -739,7 +745,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 == 1 || (opt->type == 3 && router)) + if (opt->type == 53 || opt->type == 54 || opt->type == 51 || opt->type == 58 || 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 163c0847..58473036 100644 --- a/accel-pppd/ctrl/ipoe/dhcpv4.h +++ b/accel-pppd/ctrl/ipoe/dhcpv4.h @@ -113,7 +113,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 router, 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, int renew_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 d287604b..94ce4858 100644 --- a/accel-pppd/ctrl/ipoe/ipoe.c +++ b/accel-pppd/ctrl/ipoe/ipoe.c @@ -118,6 +118,7 @@ static int conf_attr_dhcp_client_ip; static int conf_attr_dhcp_router_ip; static int conf_attr_dhcp_mask; static int conf_attr_dhcp_lease_time; +static int conf_attr_dhcp_renew_time; static int conf_attr_l4_redirect; static int conf_attr_l4_redirect_table; static int conf_attr_l4_redirect_ipset; @@ -146,6 +147,7 @@ static LIST_HEAD(conf_gw_addr); static int conf_netmask = 24; static int conf_lease_time = 600; static int conf_lease_timeout = 660; +static int conf_renew_time = 300; static int conf_verbose; static const char *conf_agent_remote_id; static int conf_proto; @@ -766,7 +768,7 @@ static void __ipoe_session_start(struct ipoe_session *ses) if (ses->ses.ipv4 && !ses->ses.ipv4->addr) ses->ses.ipv4->addr = ses->siaddr; - 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_send_reply(DHCPOFFER, ses->serv->dhcpv4, ses->dhcpv4_request, ses->yiaddr, ses->siaddr, ses->router, ses->mask, ses->lease_time, ses->renew_time, ses->dhcpv4_relay_reply); dhcpv4_packet_free(ses->dhcpv4_request); ses->dhcpv4_request = NULL; @@ -950,7 +952,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->dhcpv4 ?: ses->serv->dhcpv4, ses->dhcpv4_request, ses->yiaddr, ses->siaddr, ses->router, ses->mask, ses->lease_time, ses->dhcpv4_relay_reply); + dhcpv4_send_reply(DHCPACK, ses->dhcpv4 ?: ses->serv->dhcpv4, ses->dhcpv4_request, ses->yiaddr, ses->siaddr, ses->router, ses->mask, ses->lease_time, ses->renew_time, ses->dhcpv4_relay_reply); else dhcpv4_send_nak(ses->serv->dhcpv4, ses->dhcpv4_request); @@ -1005,7 +1007,7 @@ static void ipoe_session_keepalive(struct dhcpv4_packet *pack) } if (ses->ses.state == AP_STATE_ACTIVE) { - dhcpv4_send_reply(DHCPACK, ses->dhcpv4 ?: ses->serv->dhcpv4, ses->dhcpv4_request, ses->yiaddr, ses->siaddr, ses->router, ses->mask, ses->lease_time, ses->dhcpv4_relay_reply); + dhcpv4_send_reply(DHCPACK, ses->dhcpv4 ?: ses->serv->dhcpv4, ses->dhcpv4_request, ses->yiaddr, ses->siaddr, ses->router, ses->mask, ses->lease_time, ses->renew_time, ses->dhcpv4_relay_reply); } else dhcpv4_send_nak(ses->dhcpv4 ?: ses->serv->dhcpv4, ses->dhcpv4_request); @@ -1191,6 +1193,7 @@ static struct ipoe_session *ipoe_session_create_dhcpv4(struct ipoe_serv *serv, s memcpy(ses->hwaddr, pack->hdr->chaddr, 6); ses->giaddr = pack->hdr->giaddr; ses->lease_time = conf_lease_time; + ses->renew_time = conf_renew_time; if (pack->client_id) dlen += sizeof(struct dhcpv4_option) + pack->client_id->len; @@ -1340,7 +1343,7 @@ static void ipoe_ses_recv_dhcpv4(struct dhcpv4_serv *dhcpv4, struct dhcpv4_packe dhcpv4_packet_ref(pack); ipoe_session_keepalive(pack); } else - dhcpv4_send_reply(DHCPOFFER, dhcpv4, pack, ses->yiaddr, ses->siaddr, ses->router, 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->renew_time, ses->dhcpv4_relay_reply); } } else if (pack->msg_type == DHCPREQUEST) { ses->xid = pack->hdr->xid; @@ -1375,7 +1378,7 @@ static void ipoe_ses_recv_dhcpv4_discover(struct dhcpv4_packet *pack) } if (ses->yiaddr) - dhcpv4_send_reply(DHCPOFFER, ses->dhcpv4 ?: ses->serv->dhcpv4, pack, ses->yiaddr, ses->siaddr, ses->router, ses->mask, ses->lease_time, ses->dhcpv4_relay_reply); + dhcpv4_send_reply(DHCPOFFER, ses->dhcpv4 ?: ses->serv->dhcpv4, pack, ses->yiaddr, ses->siaddr, ses->router, ses->mask, ses->lease_time, ses->renew_time, ses->dhcpv4_relay_reply); dhcpv4_packet_free(pack); } @@ -1703,6 +1706,10 @@ static void ipoe_ses_recv_dhcpv4_relay(struct dhcpv4_packet *pack) if (opt) ses->lease_time = ntohl(*(uint32_t *)opt->data); + opt = dhcpv4_packet_find_opt(pack, 58); + if (opt) + ses->renew_time = ntohl(*(uint32_t *)opt->data); + opt = dhcpv4_packet_find_opt(pack, 1); if (opt) ses->mask = parse_dhcpv4_mask(ntohl(*(uint32_t *)opt->data)); @@ -1724,12 +1731,12 @@ static void ipoe_ses_recv_dhcpv4_relay(struct dhcpv4_packet *pack) __ipoe_session_start(ses); } else - dhcpv4_send_reply(DHCPOFFER, ses->dhcpv4 ?: ses->serv->dhcpv4, ses->dhcpv4_request, ses->yiaddr, ses->siaddr, ses->router, ses->mask, ses->lease_time, ses->dhcpv4_relay_reply); + dhcpv4_send_reply(DHCPOFFER, ses->dhcpv4 ?: ses->serv->dhcpv4, ses->dhcpv4_request, ses->yiaddr, ses->siaddr, ses->router, ses->mask, ses->lease_time, ses->renew_time, ses->dhcpv4_relay_reply); } else if (pack->msg_type == DHCPACK) { if (ses->ses.state == AP_STATE_STARTING) __ipoe_session_activate(ses); else - dhcpv4_send_reply(DHCPACK, ses->dhcpv4 ?: ses->serv->dhcpv4, ses->dhcpv4_request, ses->yiaddr, ses->siaddr, ses->router, ses->mask, ses->lease_time, ses->dhcpv4_relay_reply); + dhcpv4_send_reply(DHCPACK, ses->dhcpv4 ?: ses->serv->dhcpv4, ses->dhcpv4_request, ses->yiaddr, ses->siaddr, ses->router, ses->mask, ses->lease_time, ses->renew_time, ses->dhcpv4_relay_reply); } else if (pack->msg_type == DHCPNAK) { dhcpv4_send_nak(ses->dhcpv4 ?: ses->serv->dhcpv4, ses->dhcpv4_request); @@ -1928,6 +1935,8 @@ static void ev_radius_access_accept(struct ev_radius_t *ev) ses->l4_redirect = 1; } else if (attr->attr->id == conf_attr_dhcp_lease_time) ses->lease_time = attr->val.integer; + else if (attr->attr->id == conf_attr_dhcp_renew_time) + ses->renew_time = attr->val.integer; else if (attr->attr->id == conf_attr_l4_redirect_table) ses->l4_redirect_table = attr->val.integer; else if (attr->attr->id == conf_attr_l4_redirect_ipset) { @@ -1959,6 +1968,8 @@ static void ev_radius_coa(struct ev_radius_t *ev) ipoe_change_addr(ses, attr->val.ipaddr); } else if (attr->attr->id == conf_attr_dhcp_lease_time) ses->lease_time = attr->val.integer; + else if (attr->attr->id == conf_attr_dhcp_renew_time) + ses->renew_time = attr->val.integer; else if (attr->attr->id == conf_attr_l4_redirect_table) ses->l4_redirect_table = attr->val.integer; else if (attr->attr->id == conf_attr_l4_redirect_ipset) { @@ -2809,6 +2820,7 @@ static void load_radius_attrs(void) parse_conf_rad_attr("attr-dhcp-router-ip", &conf_attr_dhcp_router_ip); parse_conf_rad_attr("attr-dhcp-mask", &conf_attr_dhcp_mask); parse_conf_rad_attr("attr-dhcp-lease-time", &conf_attr_dhcp_lease_time); + parse_conf_rad_attr("attr-dhcp-renew-time", &conf_attr_dhcp_renew_time); parse_conf_rad_attr("attr-l4-redirect", &conf_attr_l4_redirect); parse_conf_rad_attr("attr-l4-redirect-table", &conf_attr_l4_redirect_table); parse_conf_rad_attr("attr-l4-redirect-ipset", &conf_attr_l4_redirect_ipset); @@ -3134,6 +3146,12 @@ static void load_config(void) else conf_lease_time = 600; + opt = conf_get_opt("ipoe", "renew-time"); + if (opt) + conf_renew_time = atoi(opt); + else + conf_renew_time = conf_lease_time/2; + opt = conf_get_opt("ipoe", "max-lease-time"); if (opt) conf_lease_timeout = atoi(opt); diff --git a/accel-pppd/ctrl/ipoe/ipoe.h b/accel-pppd/ctrl/ipoe/ipoe.h index f14bb5dc..6f590758 100644 --- a/accel-pppd/ctrl/ipoe/ipoe.h +++ b/accel-pppd/ctrl/ipoe/ipoe.h @@ -76,6 +76,7 @@ struct ipoe_session { char *l4_redirect_ipset; int mask; int lease_time; + int renew_time; uint8_t *data; struct dhcpv4_packet *dhcpv4_request; struct dhcpv4_packet *dhcpv4_relay_reply; |