diff options
author | Guillaume Nault <g.nault@alphalink.fr> | 2013-06-06 14:25:19 +0200 |
---|---|---|
committer | Dmitry Kozlov <xeb@mail.ru> | 2013-06-06 17:26:40 +0400 |
commit | ceb67a14759f6c132358af507a8e92a20cdbada1 (patch) | |
tree | 1f3ee94b94afdd17242ea383c81840276d6df6f4 /accel-pppd | |
parent | 386ad8576077fedb7ed83c2bea078c1082701b03 (diff) | |
download | accel-ppp-ceb67a14759f6c132358af507a8e92a20cdbada1.tar.gz accel-ppp-ceb67a14759f6c132358af507a8e92a20cdbada1.zip |
l2tp: Add src/dst port selection for creating tunnels
Add two options to the 'l2tp create tunnel' command:
* 'peer-port' allows to specify the destination port of the
SCCRQ packet (instead of standard port 1701). This allows
to connect to a peer listening on a non standard port.
* 'host-port' allows to specify the source port of the SCCRQ
packet (instead of an arbitrary free port).
Signed-off-by: Guillaume Nault <g.nault@alphalink.fr>
Diffstat (limited to 'accel-pppd')
-rw-r--r-- | accel-pppd/ctrl/l2tp/l2tp.c | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/accel-pppd/ctrl/l2tp/l2tp.c b/accel-pppd/ctrl/l2tp/l2tp.c index df8fda6..5f73193 100644 --- a/accel-pppd/ctrl/l2tp/l2tp.c +++ b/accel-pppd/ctrl/l2tp/l2tp.c @@ -3608,10 +3608,14 @@ static int l2tp_create_tunnel_exec(const char *cmd, char * const *fields, { struct l2tp_conn_t *conn = NULL; struct sockaddr_in peer = { - .sin_family = AF_UNSPEC + .sin_family = AF_INET, + .sin_port = htons(L2TP_PORT), + .sin_addr = { htonl(INADDR_ANY) } }; struct sockaddr_in host = { - .sin_family = AF_UNSPEC + .sin_family = AF_INET, + .sin_port = 0, + .sin_addr = { htonl(INADDR_ANY) } }; const char *opt = NULL; int peer_indx = -1; @@ -3642,8 +3646,6 @@ static int l2tp_create_tunnel_exec(const char *cmd, char * const *fields, } } else if (strcmp("peer-addr", fields[indx]) == 0) { peer_indx = ++indx; - peer.sin_family = AF_INET; - peer.sin_port = htons(L2TP_PORT); if (inet_aton(fields[indx], &peer.sin_addr) == 0) { cli_sendv(client, "invalid peer address: \"%s\"\r\n", @@ -3652,14 +3654,34 @@ static int l2tp_create_tunnel_exec(const char *cmd, char * const *fields, } } else if (strcmp("host-addr", fields[indx]) == 0) { host_indx = ++indx; - host.sin_family = AF_INET; - host.sin_port = 0; if (inet_aton(fields[indx], &host.sin_addr) == 0) { cli_sendv(client, "invalid host address: \"%s\"\r\n", fields[indx]); return CLI_CMD_INVAL; } + } else if (strcmp("peer-port", fields[indx]) == 0) { + long port; + ++indx; + if (u_readlong(&port, fields[indx], + 0, UINT16_MAX) < 0) { + cli_sendv(client, + "invalid peer port: \"%s\"\r\n", + fields[indx]); + return CLI_CMD_INVAL; + } + peer.sin_port = htons(port); + } else if (strcmp("host-port", fields[indx]) == 0) { + long port; + ++indx; + if (u_readlong(&port, fields[indx], + 0, UINT16_MAX) < 0) { + cli_sendv(client, + "invalid host port: \"%s\"\r\n", + fields[indx]); + return CLI_CMD_INVAL; + } + host.sin_port = htons(port); } else if (strcmp("hide-avps", fields[indx]) == 0) { ++indx; hide_avps = atoi(fields[indx]) > 0; @@ -3755,7 +3777,8 @@ static void l2tp_create_tunnel_help(char * const *fields, int fields_cnt, void *client) { cli_send(client, - "l2tp create tunnel peer-addr <ip_addr> [host-addr <ip_addr>]" + "l2tp create tunnel peer-addr <ip_addr> [peer-port <port>]" + " [host-addr <ip_addr>] [host-port <port>]" " [hide-avps <0|1>] [mode <lac|lns>]" " - initiate new tunnel to peer\r\n"); } |