version 1.1.1.2, 2013/07/22 08:44:29
|
version 1.1.1.3, 2016/11/01 09:56:12
|
Line 28
|
Line 28
|
#include <netgraph/ng_ksocket.h> |
#include <netgraph/ng_ksocket.h> |
#include <netgraph/ng_l2tp.h> |
#include <netgraph/ng_l2tp.h> |
#include <netgraph.h> |
#include <netgraph.h> |
|
#include <fnmatch.h> |
|
|
/* |
/* |
* DEFINITIONS |
* DEFINITIONS |
Line 74
|
Line 75
|
char hostname[MAXHOSTNAMELEN]; /* L2TP local hostname */ |
char hostname[MAXHOSTNAMELEN]; /* L2TP local hostname */ |
char secret[64]; /* L2TP tunnel secret */ |
char secret[64]; /* L2TP tunnel secret */ |
char *fqdn_peer_addr; /* FQDN Peer address */ |
char *fqdn_peer_addr; /* FQDN Peer address */ |
|
char *peer_mask; /* L2TP peer hostname mask */ |
} conf; |
} conf; |
u_char opened; /* L2TP opened by phys */ |
u_char opened; /* L2TP opened by phys */ |
u_char incoming; /* Call is incoming vs. outgoing */ |
u_char incoming; /* Call is incoming vs. outgoing */ |
Line 94
|
Line 96
|
SET_CALLINGNUM, |
SET_CALLINGNUM, |
SET_CALLEDNUM, |
SET_CALLEDNUM, |
SET_HOSTNAME, |
SET_HOSTNAME, |
|
SET_PEERMASK, |
SET_SECRET, |
SET_SECRET, |
SET_ENABLE, |
SET_ENABLE, |
SET_DISABLE |
SET_DISABLE |
Line 209
|
Line 212
|
L2tpSetCommand, NULL, 2, (void *) SET_CALLEDNUM }, |
L2tpSetCommand, NULL, 2, (void *) SET_CALLEDNUM }, |
{ "hostname {name}", "Set L2TP local hostname", |
{ "hostname {name}", "Set L2TP local hostname", |
L2tpSetCommand, NULL, 2, (void *) SET_HOSTNAME }, |
L2tpSetCommand, NULL, 2, (void *) SET_HOSTNAME }, |
|
{ "pmask {mask}", "Set L2TP peer hostname mask", |
|
L2tpSetCommand, NULL, 2, (void *) SET_PEERMASK }, |
{ "secret {sec}", "Set L2TP tunnel secret", |
{ "secret {sec}", "Set L2TP tunnel secret", |
L2tpSetCommand, NULL, 2, (void *) SET_SECRET }, |
L2tpSetCommand, NULL, 2, (void *) SET_SECRET }, |
{ "enable [opt ...]", "Enable option", |
{ "enable [opt ...]", "Enable option", |
Line 298 L2tpInit(Link l)
|
Line 303 L2tpInit(Link l)
|
l2tp->conf.peer_addr.width = 0; |
l2tp->conf.peer_addr.width = 0; |
l2tp->conf.peer_port = 0; |
l2tp->conf.peer_port = 0; |
l2tp->conf.fqdn_peer_addr = NULL; |
l2tp->conf.fqdn_peer_addr = NULL; |
|
l2tp->conf.peer_mask = NULL; |
|
|
Enable(&l2tp->conf.options, L2TP_CONF_DATASEQ); |
Enable(&l2tp->conf.options, L2TP_CONF_DATASEQ); |
Enable(&l2tp->conf.options, L2TP_CONF_RESOLVE_ONCE); |
Enable(&l2tp->conf.options, L2TP_CONF_RESOLVE_ONCE); |
Line 320 L2tpInst(Link l, Link lt)
|
Line 326 L2tpInst(Link l, Link lt)
|
if (pit->conf.fqdn_peer_addr != NULL) |
if (pit->conf.fqdn_peer_addr != NULL) |
pi->conf.fqdn_peer_addr = |
pi->conf.fqdn_peer_addr = |
Mstrdup(MB_PHYS, pit->conf.fqdn_peer_addr); |
Mstrdup(MB_PHYS, pit->conf.fqdn_peer_addr); |
|
if (pit->conf.peer_mask != NULL) |
|
pi->conf.peer_mask = Mstrdup(MB_PHYS, pit->conf.peer_mask); |
if (pi->server) |
if (pi->server) |
pi->server->refs++; |
pi->server->refs++; |
|
|
Line 512 L2tpOpen(Link l)
|
Line 520 L2tpOpen(Link l)
|
win = htons(8); /* XXX: this value is empirical. */ |
win = htons(8); /* XXX: this value is empirical. */ |
if ((ppp_l2tp_avp_list_append(avps, 1, 0, AVP_HOST_NAME, |
if ((ppp_l2tp_avp_list_append(avps, 1, 0, AVP_HOST_NAME, |
hostname, strlen(hostname)) == -1) || |
hostname, strlen(hostname)) == -1) || |
(ppp_l2tp_avp_list_append(avps, 1, 0, AVP_VENDOR_NAME, | (ppp_l2tp_avp_list_append(avps, 0, 0, AVP_VENDOR_NAME, |
MPD_VENDOR, strlen(MPD_VENDOR)) == -1) || |
MPD_VENDOR, strlen(MPD_VENDOR)) == -1) || |
(ppp_l2tp_avp_list_append(avps, 1, 0, AVP_BEARER_CAPABILITIES, |
(ppp_l2tp_avp_list_append(avps, 1, 0, AVP_BEARER_CAPABILITIES, |
&cap, sizeof(cap)) == -1) || |
&cap, sizeof(cap)) == -1) || |
Line 680 L2tpShutdown(Link l)
|
Line 688 L2tpShutdown(Link l)
|
|
|
if (pi->conf.fqdn_peer_addr) |
if (pi->conf.fqdn_peer_addr) |
Freee(pi->conf.fqdn_peer_addr); |
Freee(pi->conf.fqdn_peer_addr); |
| if (pi->conf.peer_mask) |
| Freee(pi->conf.peer_mask); |
L2tpUnListen(l); |
L2tpUnListen(l); |
Freee(l->info); |
Freee(l->info); |
} |
} |
Line 911 L2tpStat(Context ctx)
|
Line 920 L2tpStat(Context ctx)
|
Printf(", port %u", l2tp->conf.peer_port); |
Printf(", port %u", l2tp->conf.peer_port); |
Printf("\r\n"); |
Printf("\r\n"); |
Printf("\tHostname : %s\r\n", l2tp->conf.hostname); |
Printf("\tHostname : %s\r\n", l2tp->conf.hostname); |
|
Printf("\tPeer mask : %s\r\n", l2tp->conf.peer_mask); |
Printf("\tSecret : %s\r\n", (l2tp->conf.callingnum[0])?"******":""); |
Printf("\tSecret : %s\r\n", (l2tp->conf.callingnum[0])?"******":""); |
Printf("\tCalling number: %s\r\n", l2tp->conf.callingnum); |
Printf("\tCalling number: %s\r\n", l2tp->conf.callingnum); |
Printf("\tCalled number: %s\r\n", l2tp->conf.callednum); |
Printf("\tCalled number: %s\r\n", l2tp->conf.callednum); |
Line 1103 ppp_l2tp_initiated_cb(struct ppp_l2tp_ctrl *ctrl,
|
Line 1113 ppp_l2tp_initiated_cb(struct ppp_l2tp_ctrl *ctrl,
|
u_char *include_length, u_char *enable_dseq) |
u_char *include_length, u_char *enable_dseq) |
{ |
{ |
struct l2tp_tun *const tun = ppp_l2tp_ctrl_get_cookie(ctrl); |
struct l2tp_tun *const tun = ppp_l2tp_ctrl_get_cookie(ctrl); |
|
char *peername = ppp_l2tp_ctrl_get_peer_name_p(ctrl); |
struct ppp_l2tp_avp_ptrs *ptrs = NULL; |
struct ppp_l2tp_avp_ptrs *ptrs = NULL; |
Link l = NULL; |
Link l = NULL; |
L2tpInfo pi = NULL; |
L2tpInfo pi = NULL; |
Line 1146 ppp_l2tp_initiated_cb(struct ppp_l2tp_ctrl *ctrl,
|
Line 1157 ppp_l2tp_initiated_cb(struct ppp_l2tp_ctrl *ctrl,
|
((u_addrempty(&pi2->conf.self_addr)) || (u_addrcompare(&pi2->conf.self_addr, &tun->self_addr) == 0)) && |
((u_addrempty(&pi2->conf.self_addr)) || (u_addrcompare(&pi2->conf.self_addr, &tun->self_addr) == 0)) && |
(pi2->conf.self_port == 0 || pi2->conf.self_port == tun->self_port) && |
(pi2->conf.self_port == 0 || pi2->conf.self_port == tun->self_port) && |
(IpAddrInRange(&pi2->conf.peer_addr, &tun->peer_addr)) && |
(IpAddrInRange(&pi2->conf.peer_addr, &tun->peer_addr)) && |
(pi2->conf.peer_port == 0 || pi2->conf.peer_port == tun->peer_port)) { | (pi2->conf.peer_port == 0 || pi2->conf.peer_port == tun->peer_port) && |
| (peername == NULL || *peername == 0 || pi2->conf.peer_mask == 0 || fnmatch(pi2->conf.peer_mask, peername, 0) == 0)) { |
|
|
if (pi == NULL || pi2->conf.peer_addr.width > pi->conf.peer_addr.width) { |
if (pi == NULL || pi2->conf.peer_addr.width > pi->conf.peer_addr.width) { |
l = l2; |
l = l2; |
Line 1165 ppp_l2tp_initiated_cb(struct ppp_l2tp_ctrl *ctrl,
|
Line 1177 ppp_l2tp_initiated_cb(struct ppp_l2tp_ctrl *ctrl,
|
Log(LG_PHYS, ("[%s] L2TP: %s call #%u via control connection %p accepted", |
Log(LG_PHYS, ("[%s] L2TP: %s call #%u via control connection %p accepted", |
l->name, (out?"Outgoing":"Incoming"), |
l->name, (out?"Outgoing":"Incoming"), |
ppp_l2tp_sess_get_serial(sess), ctrl)); |
ppp_l2tp_sess_get_serial(sess), ctrl)); |
|
if (peername && *peername) |
|
Log(LG_PHYS2, ("[%s] L2TP: Call #%u remote hostname is %s", |
|
l->name, ppp_l2tp_sess_get_serial(sess), peername)); |
|
|
if (out) |
if (out) |
l->state = PHYS_STATE_READY; |
l->state = PHYS_STATE_READY; |
Line 1711 L2tpSetCommand(Context ctx, int ac, char *av[], void *
|
Line 1726 L2tpSetCommand(Context ctx, int ac, char *av[], void *
|
{ |
{ |
L2tpInfo const l2tp = (L2tpInfo) ctx->lnk->info; |
L2tpInfo const l2tp = (L2tpInfo) ctx->lnk->info; |
char **fqdn_peer_addr = &l2tp->conf.fqdn_peer_addr; |
char **fqdn_peer_addr = &l2tp->conf.fqdn_peer_addr; |
|
char **peer_mask = &l2tp->conf.peer_mask; |
struct u_range rng; |
struct u_range rng; |
int port; |
int port; |
|
|
Line 1756 L2tpSetCommand(Context ctx, int ac, char *av[], void *
|
Line 1772 L2tpSetCommand(Context ctx, int ac, char *av[], void *
|
if (ac != 1) |
if (ac != 1) |
return(-1); |
return(-1); |
strlcpy(l2tp->conf.hostname, av[0], sizeof(l2tp->conf.hostname)); |
strlcpy(l2tp->conf.hostname, av[0], sizeof(l2tp->conf.hostname)); |
|
break; |
|
case SET_PEERMASK: |
|
if (ac != 1) |
|
return(-1); |
|
if (*peer_mask) |
|
Freee(*peer_mask); |
|
*peer_mask = Mstrdup(MB_PHYS, av[0]); |
break; |
break; |
case SET_SECRET: |
case SET_SECRET: |
if (ac != 1) |
if (ac != 1) |