summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKozlov Dmitry <xeb@mail.ru>2013-01-26 12:09:20 +0400
committerKozlov Dmitry <xeb@mail.ru>2013-01-26 12:09:20 +0400
commit9090b3c07b7b03be624599aa09be16ee85d06745 (patch)
tree6641353564097a830353969369426abb94f76f2f
parentb4d2b981d0644855124a035e673d7eef3900e614 (diff)
downloadaccel-ppp-9090b3c07b7b03be624599aa09be16ee85d06745.tar.gz
accel-ppp-9090b3c07b7b03be624599aa09be16ee85d06745.zip
ipoe: insert opt82 to each relay packet
-rw-r--r--accel-pppd/ctrl/ipoe/dhcpv4.c19
-rw-r--r--accel-pppd/ctrl/ipoe/dhcpv4.h6
-rw-r--r--accel-pppd/ctrl/ipoe/ipoe.c17
3 files changed, 25 insertions, 17 deletions
diff --git a/accel-pppd/ctrl/ipoe/dhcpv4.c b/accel-pppd/ctrl/ipoe/dhcpv4.c
index 0c43b944..e5a8731e 100644
--- a/accel-pppd/ctrl/ipoe/dhcpv4.c
+++ b/accel-pppd/ctrl/ipoe/dhcpv4.c
@@ -891,7 +891,7 @@ void dhcpv4_relay_free(struct dhcpv4_relay *r, struct triton_context_t *ctx)
}
}
-int dhcpv4_relay_send(struct dhcpv4_relay *relay, struct dhcpv4_packet *request, uint32_t server_id)
+int dhcpv4_relay_send(struct dhcpv4_relay *relay, struct dhcpv4_packet *request, uint32_t server_id, const char *agent_circuit_id, const char *agent_remote_id)
{
int n;
int len = request->ptr - request->data;
@@ -899,6 +899,9 @@ int dhcpv4_relay_send(struct dhcpv4_relay *relay, struct dhcpv4_packet *request,
struct dhcpv4_option *opt = NULL;
uint32_t _server_id;
+ if (!request->relay_agent && dhcpv4_packet_insert_opt82(request, agent_circuit_id, agent_remote_id))
+ return -1;
+
request->hdr->giaddr = relay->giaddr;
if (server_id) {
@@ -914,6 +917,7 @@ int dhcpv4_relay_send(struct dhcpv4_relay *relay, struct dhcpv4_packet *request,
dhcpv4_print_packet(request, 1, log_ppp_info2);
}
+ len = request->ptr - request->data;
n = write(relay->hnd.fd, request->data, len);
request->hdr->giaddr = giaddr;
@@ -928,7 +932,8 @@ int dhcpv4_relay_send(struct dhcpv4_relay *relay, struct dhcpv4_packet *request,
}
int dhcpv4_relay_send_release(struct dhcpv4_relay *relay, uint8_t *chaddr, uint32_t xid, uint32_t ciaddr,
- struct dhcpv4_option *client_id, struct dhcpv4_option *relay_agent)
+ struct dhcpv4_option *client_id, struct dhcpv4_option *relay_agent,
+ const char *agent_circuit_id, const char *agent_remote_id)
{
struct dhcpv4_packet *pack;
int n, len;
@@ -959,8 +964,14 @@ int dhcpv4_relay_send_release(struct dhcpv4_relay *relay, uint8_t *chaddr, uint3
if (relay_agent && dhcpv4_packet_add_opt(pack, 82, relay_agent->data, relay_agent->len))
goto out_err;
-
- *pack->ptr = 255; pack->ptr++;
+ else if (!relay_agent) {
+ pack->ptr++;
+ if (dhcpv4_packet_insert_opt82(pack, agent_circuit_id, agent_remote_id))
+ goto out_err;
+ pack->ptr--;
+ }
+
+ *pack->ptr++ = 255;
len = pack->ptr - pack->data;
diff --git a/accel-pppd/ctrl/ipoe/dhcpv4.h b/accel-pppd/ctrl/ipoe/dhcpv4.h
index a6a445b3..cea0934c 100644
--- a/accel-pppd/ctrl/ipoe/dhcpv4.h
+++ b/accel-pppd/ctrl/ipoe/dhcpv4.h
@@ -105,9 +105,11 @@ void dhcpv4_free(struct dhcpv4_serv *);
struct dhcpv4_relay *dhcpv4_relay_create(const char *addr, const char *giaddr, struct triton_context_t *ctx, triton_event_func recv);
void dhcpv4_relay_free(struct dhcpv4_relay *, struct triton_context_t *);
-int dhcpv4_relay_send(struct dhcpv4_relay *relay, struct dhcpv4_packet *request, uint32_t server_id);
+int dhcpv4_relay_send(struct dhcpv4_relay *relay, struct dhcpv4_packet *request, uint32_t server_id,
+ const char *agent_circuit_id, const char *agent_remote_id);
int dhcpv4_relay_send_release(struct dhcpv4_relay *relay, uint8_t *chaddr, uint32_t xid, uint32_t ciaddr,
- struct dhcpv4_option *client_id, struct dhcpv4_option *relay_agent);
+ 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_nak(struct dhcpv4_serv *serv, struct dhcpv4_packet *req);
diff --git a/accel-pppd/ctrl/ipoe/ipoe.c b/accel-pppd/ctrl/ipoe/ipoe.c
index 7c74e565..6ba069bf 100644
--- a/accel-pppd/ctrl/ipoe/ipoe.c
+++ b/accel-pppd/ctrl/ipoe/ipoe.c
@@ -401,12 +401,7 @@ static void ipoe_session_start(struct ipoe_session *ses)
}
if (ses->dhcpv4_request && ses->serv->dhcpv4_relay) {
- if (!ses->dhcpv4_request->relay_agent && dhcpv4_packet_insert_opt82(ses->dhcpv4_request, ses->serv->ifname, conf_agent_remote_id)) {
- ap_session_terminate(&ses->ses, TERM_NAS_ERROR, 0);
- return;
- }
-
- dhcpv4_relay_send(ses->serv->dhcpv4_relay, ses->dhcpv4_request, ses->relay_server_id);
+ dhcpv4_relay_send(ses->serv->dhcpv4_relay, ses->dhcpv4_request, ses->relay_server_id, ses->serv->ifname, conf_agent_remote_id);
ses->timer.expire = ipoe_session_timeout;
ses->timer.expire_tv.tv_sec = conf_offer_timeout;
@@ -588,7 +583,7 @@ static void __ipoe_session_activate(struct ipoe_session *ses)
static void ipoe_session_activate(struct ipoe_session *ses)
{
if (ses->serv->dhcpv4_relay)
- dhcpv4_relay_send(ses->serv->dhcpv4_relay, ses->dhcpv4_request, ses->relay_server_id);
+ dhcpv4_relay_send(ses->serv->dhcpv4_relay, ses->dhcpv4_request, ses->relay_server_id, ses->serv->ifname, conf_agent_remote_id);
else
__ipoe_session_activate(ses);
}
@@ -608,7 +603,7 @@ static void ipoe_session_keepalive(struct dhcpv4_packet *pack)
ses->xid = ses->dhcpv4_request->hdr->xid;
if (ses->ses.state == AP_STATE_ACTIVE && ses->serv->dhcpv4_relay) {
- dhcpv4_relay_send(ses->serv->dhcpv4_relay, ses->dhcpv4_request, ses->relay_server_id);
+ dhcpv4_relay_send(ses->serv->dhcpv4_relay, ses->dhcpv4_request, ses->relay_server_id, ses->serv->ifname, conf_agent_remote_id);
return;
}
@@ -685,7 +680,7 @@ static void ipoe_session_finished(struct ap_session *s)
dhcpv4_put_ip(ses->serv->dhcpv4, ses->yiaddr);
if (ses->relay_addr && ses->serv->dhcpv4_relay)
- dhcpv4_relay_send_release(ses->serv->dhcpv4_relay, ses->hwaddr, ses->xid, ses->yiaddr, ses->client_id, ses->relay_agent);
+ dhcpv4_relay_send_release(ses->serv->dhcpv4_relay, ses->hwaddr, ses->xid, ses->yiaddr, ses->client_id, ses->relay_agent, ses->serv->ifname, conf_agent_remote_id);
if (ses->ifcfg)
ipoe_ifcfg_del(ses);
@@ -862,7 +857,7 @@ static void ipoe_recv_dhcpv4(struct dhcpv4_serv *dhcpv4, struct dhcpv4_packet *p
if (pack->server_id == ses->siaddr)
dhcpv4_send_nak(dhcpv4, pack);
else if (ses->serv->dhcpv4_relay)
- dhcpv4_relay_send(ses->serv->dhcpv4_relay, pack, 0);
+ dhcpv4_relay_send(ses->serv->dhcpv4_relay, pack, 0, ses->serv->ifname, conf_agent_remote_id);
ap_session_terminate(&ses->ses, TERM_USER_REQUEST, 0);
} else {
@@ -895,7 +890,7 @@ static void ipoe_recv_dhcpv4(struct dhcpv4_serv *dhcpv4, struct dhcpv4_packet *p
}
if (pack->msg_type == DHCPDECLINE && ses->serv->dhcpv4_relay)
- dhcpv4_relay_send(ses->serv->dhcpv4_relay, pack, 0);
+ dhcpv4_relay_send(ses->serv->dhcpv4_relay, pack, 0, ses->serv->ifname, conf_agent_remote_id);
ap_session_terminate(&ses->ses, TERM_USER_REQUEST, 0);
}