summaryrefslogtreecommitdiff
path: root/accel-pppd
diff options
context:
space:
mode:
authorGuillaume Nault <g.nault@alphalink.fr>2013-02-11 21:01:39 +0100
committerKozlov Dmitry <xeb@mail.ru>2013-02-12 00:12:47 +0400
commit7834f4db6be704c37e043f229bed1142eacc8903 (patch)
tree3f9b6d0ba9fa6506dffb5e3da5416b02b5261334 /accel-pppd
parent2ef53e8225299b74454ab37842814b53c911c04a (diff)
downloadaccel-ppp-xebd-7834f4db6be704c37e043f229bed1142eacc8903.tar.gz
accel-ppp-xebd-7834f4db6be704c37e043f229bed1142eacc8903.zip
l2tp: Pass host address as sockaddr in tunnel alloc.
Pass the host address as a directly usable sockaddr_in in l2tp_tunnel_alloc(), instead of an in_pktinfo. This will allow to allocate tunnels without having to artificially create in_pktinfo structures in situations where the tunnel is not created in response to an SCCRQ. As a side effect, this patch makes accel-ppp reply to SCCRQ using an arbitrary source port, as specified in RFC 2661. Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
Diffstat (limited to 'accel-pppd')
-rw-r--r--accel-pppd/ctrl/l2tp/l2tp.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/accel-pppd/ctrl/l2tp/l2tp.c b/accel-pppd/ctrl/l2tp/l2tp.c
index afa299d..3722915 100644
--- a/accel-pppd/ctrl/l2tp/l2tp.c
+++ b/accel-pppd/ctrl/l2tp/l2tp.c
@@ -589,12 +589,11 @@ out_err:
static struct l2tp_conn_t *l2tp_tunnel_alloc(struct l2tp_serv_t *serv,
struct l2tp_packet_t *pack,
- struct in_pktinfo *pkt_info,
+ const struct sockaddr_in *host,
uint32_t framing_cap,
struct l2tp_attr_t *challenge)
{
struct l2tp_conn_t *conn;
- struct sockaddr_in addr;
uint16_t tid;
int flag;
@@ -626,11 +625,6 @@ static struct l2tp_conn_t *l2tp_tunnel_alloc(struct l2tp_serv_t *serv,
goto out_err;
}
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_addr = pkt_info->ipi_addr;
- addr.sin_port = htons(L2TP_PORT);
-
flag = 1;
if (setsockopt(conn->hnd.fd, SOL_SOCKET, SO_REUSEADDR,
&flag, sizeof(flag)) < 0) {
@@ -638,7 +632,7 @@ static struct l2tp_conn_t *l2tp_tunnel_alloc(struct l2tp_serv_t *serv,
strerror(errno));
goto out_err;
}
- if (bind(conn->hnd.fd, &addr, sizeof(addr))) {
+ if (bind(conn->hnd.fd, host, sizeof(*host))) {
log_error("l2tp: bind: %s\n", strerror(errno));
goto out_err;
}
@@ -679,7 +673,7 @@ static struct l2tp_conn_t *l2tp_tunnel_alloc(struct l2tp_serv_t *serv,
}
memcpy(&conn->lac_addr, &pack->addr, sizeof(pack->addr));
- memcpy(&conn->lns_addr, &addr, sizeof(addr));
+ memcpy(&conn->lns_addr, host, sizeof(*host));
conn->framing_cap = framing_cap;
/* If challenge set in SCCRQ, we need to calculate response for SCCRP */
@@ -1087,6 +1081,7 @@ static int l2tp_recv_SCCRQ(struct l2tp_serv_t *serv, struct l2tp_packet_t *pack,
struct l2tp_attr_t *router_id = NULL;
struct l2tp_attr_t *challenge = NULL;
struct l2tp_conn_t *conn = NULL;
+ struct sockaddr_in host_addr = { 0 };
if (ap_shutdown)
return 0;
@@ -1138,9 +1133,12 @@ static int l2tp_recv_SCCRQ(struct l2tp_serv_t *serv, struct l2tp_packet_t *pack,
return -1;
}
- conn = l2tp_tunnel_alloc(serv, pack, pkt_info,
- framing_cap->val.uint32, challenge);
+ host_addr.sin_family = AF_INET;
+ host_addr.sin_addr = pkt_info->ipi_addr;
+ host_addr.sin_port = 0;
+ conn = l2tp_tunnel_alloc(serv, pack, &host_addr,
+ framing_cap->val.uint32, challenge);
if (conn == NULL)
return -1;