version 1.1.1.3, 2016/11/01 09:56:12
|
version 1.1.1.4.2.1, 2023/09/27 11:08:00
|
Line 144
|
Line 144
|
static void L2tpNodeUpdate(Link l); |
static void L2tpNodeUpdate(Link l); |
static int L2tpListen(Link l); |
static int L2tpListen(Link l); |
static void L2tpUnListen(Link l); |
static void L2tpUnListen(Link l); |
static int L2tpSetCommand(Context ctx, int ac, char *av[], void *arg); | static int L2tpSetCommand(Context ctx, int ac, const char *const av[], const void *arg); |
|
|
/* L2TP control callbacks */ |
/* L2TP control callbacks */ |
static ppp_l2tp_ctrl_connected_t ppp_l2tp_ctrl_connected_cb; |
static ppp_l2tp_ctrl_connected_t ppp_l2tp_ctrl_connected_cb; |
Line 220
|
Line 220
|
L2tpSetCommand, NULL, 2, (void *) SET_ENABLE }, |
L2tpSetCommand, NULL, 2, (void *) SET_ENABLE }, |
{ "disable [opt ...]", "Disable option", |
{ "disable [opt ...]", "Disable option", |
L2tpSetCommand, NULL, 2, (void *) SET_DISABLE }, |
L2tpSetCommand, NULL, 2, (void *) SET_DISABLE }, |
{ NULL }, | { NULL, NULL, NULL, NULL, 0, NULL }, |
}; |
}; |
|
|
/* |
/* |
* INTERNAL VARIABLES |
* INTERNAL VARIABLES |
*/ |
*/ |
|
|
static struct confinfo gConfList[] = { | static const struct confinfo gConfList[] = { |
{ 0, L2TP_CONF_OUTCALL, "outcall" }, |
{ 0, L2TP_CONF_OUTCALL, "outcall" }, |
{ 0, L2TP_CONF_HIDDEN, "hidden" }, |
{ 0, L2TP_CONF_HIDDEN, "hidden" }, |
{ 0, L2TP_CONF_LENGTH, "length" }, |
{ 0, L2TP_CONF_LENGTH, "length" }, |
Line 236
|
Line 236
|
{ 0, 0, NULL }, |
{ 0, 0, NULL }, |
}; |
}; |
|
|
int L2tpListenUpdateSheduled = 0; | static struct ghash *gL2tpServers; |
struct pppTimer L2tpListenUpdateTimer; | static struct ghash *gL2tpTuns; |
| static int one = 1; |
|
|
struct ghash *gL2tpServers; |
|
struct ghash *gL2tpTuns; |
|
int one = 1; |
|
|
|
/* |
/* |
* L2tpTInit() |
* L2tpTInit() |
*/ |
*/ |
Line 587 L2tpOpen(Link l)
|
Line 584 L2tpOpen(Link l)
|
goto fail; |
goto fail; |
} |
} |
|
|
if (!u_addrempty(&tun->self_addr)) { | if (!u_addrempty(&tun->self_addr) || tun->self_port != 0) { |
/* Bind socket to a new port */ |
/* Bind socket to a new port */ |
u_addrtosockaddr(&tun->self_addr,tun->self_port,&sas); |
u_addrtosockaddr(&tun->self_addr,tun->self_port,&sas); |
if (NgSendMsg(csock, namebuf, NGM_KSOCKET_COOKIE, |
if (NgSendMsg(csock, namebuf, NGM_KSOCKET_COOKIE, |
Line 860 L2tpPeerMacAddr(Link l, void *buf, size_t buf_len)
|
Line 857 L2tpPeerMacAddr(Link l, void *buf, size_t buf_len)
|
{ |
{ |
L2tpInfo const l2tp = (L2tpInfo) l->info; |
L2tpInfo const l2tp = (L2tpInfo) l->info; |
|
|
|
if (buf_len < 18) |
|
return 1; |
if (l2tp->tun && l2tp->tun->peer_iface[0]) { |
if (l2tp->tun && l2tp->tun->peer_iface[0]) { |
ether_ntoa_r((struct ether_addr *)l2tp->tun->peer_mac_addr, buf); |
ether_ntoa_r((struct ether_addr *)l2tp->tun->peer_mac_addr, buf); |
return (0); |
return (0); |
Line 1057 ppp_l2tp_ctrl_terminated_cb(struct ppp_l2tp_ctrl *ctrl
|
Line 1056 ppp_l2tp_ctrl_terminated_cb(struct ppp_l2tp_ctrl *ctrl
|
struct l2tp_tun *tun = ppp_l2tp_ctrl_get_cookie(ctrl); |
struct l2tp_tun *tun = ppp_l2tp_ctrl_get_cookie(ctrl); |
int k; |
int k; |
|
|
|
(void)result; |
Log(LG_PHYS, ("L2TP: Control connection %p terminated: %d (%s)", |
Log(LG_PHYS, ("L2TP: Control connection %p terminated: %d (%s)", |
ctrl, error, errmsg)); |
ctrl, error, errmsg)); |
|
|
Line 1190 ppp_l2tp_initiated_cb(struct ppp_l2tp_ctrl *ctrl,
|
Line 1190 ppp_l2tp_initiated_cb(struct ppp_l2tp_ctrl *ctrl,
|
pi->tun = tun; |
pi->tun = tun; |
tun->active_sessions++; |
tun->active_sessions++; |
pi->sess = sess; |
pi->sess = sess; |
if (ptrs->callingnum && ptrs->callingnum->number) | if (ptrs->callingnum) |
strlcpy(pi->callingnum, ptrs->callingnum->number, sizeof(pi->callingnum)); |
strlcpy(pi->callingnum, ptrs->callingnum->number, sizeof(pi->callingnum)); |
if (ptrs->callednum && ptrs->callednum->number) | if (ptrs->callednum) |
strlcpy(pi->callednum, ptrs->callednum->number, sizeof(pi->callednum)); |
strlcpy(pi->callednum, ptrs->callednum->number, sizeof(pi->callednum)); |
|
|
*include_length = (Enabled(&pi->conf.options, L2TP_CONF_LENGTH)?1:0); |
*include_length = (Enabled(&pi->conf.options, L2TP_CONF_LENGTH)?1:0); |
Line 1374 L2tpServerEvent(int type, void *arg)
|
Line 1374 L2tpServerEvent(int type, void *arg)
|
struct ngm_mkpeer mkpeer; |
struct ngm_mkpeer mkpeer; |
struct sockaddr_storage peer_sas; |
struct sockaddr_storage peer_sas; |
struct sockaddr_storage sas; |
struct sockaddr_storage sas; |
|
struct u_addr server_addr; |
const size_t bufsize = 8192; |
const size_t bufsize = 8192; |
u_int16_t *buf = NULL; |
u_int16_t *buf = NULL; |
char hook[NG_HOOKSIZ]; |
char hook[NG_HOOKSIZ]; |
Line 1389 L2tpServerEvent(int type, void *arg)
|
Line 1390 L2tpServerEvent(int type, void *arg)
|
u_int16_t win; |
u_int16_t win; |
int k; |
int k; |
|
|
|
(void)type; |
/* Allocate buffer */ |
/* Allocate buffer */ |
buf = Malloc(MB_PHYS, bufsize); |
buf = Malloc(MB_PHYS, bufsize); |
|
|
|
u_addrcopy(&s->self_addr, &server_addr); |
|
|
/* Read packet */ |
/* Read packet */ |
sas_len = sizeof(peer_sas); |
sas_len = sizeof(peer_sas); |
if ((len = recvfrom(s->sock, buf, bufsize, 0, | |
| if (u_addrempty(&s->self_addr)) { |
| if ((len = GetDataAddrs(s->sock, buf, bufsize, |
| &peer_sas, sas_len, &server_addr)) == -1) { |
| Perror("L2TP: GetDataAddrs"); |
| goto fail; |
| } |
| } else if ((len = recvfrom(s->sock, buf, bufsize, 0, |
(struct sockaddr *)&peer_sas, &sas_len)) == -1) { |
(struct sockaddr *)&peer_sas, &sas_len)) == -1) { |
Perror("L2TP: recvfrom"); |
Perror("L2TP: recvfrom"); |
goto fail; |
goto fail; |
Line 1414 L2tpServerEvent(int type, void *arg)
|
Line 1425 L2tpServerEvent(int type, void *arg)
|
tun->self_port = s->self_port; |
tun->self_port = s->self_port; |
tun->alive = 1; |
tun->alive = 1; |
|
|
Log(LG_PHYS, ("Incoming L2TP packet from %s %d", | if (u_addrempty(&tun->self_addr)) |
u_addrtoa(&tun->peer_addr, namebuf, sizeof(namebuf)), tun->peer_port)); | u_addrcopy(&server_addr, &tun->self_addr); |
|
|
|
if (u_addrempty(&tun->self_addr)) |
|
Log(LG_PHYS, ("Incoming L2TP packet from %s %d", |
|
u_addrtoa(&tun->peer_addr, namebuf, sizeof(namebuf)), |
|
tun->peer_port)); |
|
else { |
|
char buf3[INET_ADDRSTRLEN]; |
|
|
|
Log(LG_PHYS, ("Incoming L2TP packet from %s %d to %s %d", |
|
u_addrtoa(&tun->peer_addr, namebuf, sizeof(namebuf)), |
|
tun->peer_port, |
|
u_addrtoa(&tun->self_addr, buf3, sizeof(buf3)), |
|
tun->self_port)); |
|
} |
|
|
/* Examine all L2TP links to get best possible fit tunnel parameters. */ |
/* Examine all L2TP links to get best possible fit tunnel parameters. */ |
for (k = 0; k < gNumLinks; k++) { |
for (k = 0; k < gNumLinks; k++) { |
Link l2; |
Link l2; |
Line 1551 L2tpServerEvent(int type, void *arg)
|
Line 1576 L2tpServerEvent(int type, void *arg)
|
} |
} |
|
|
/* Bind socket to a new port */ |
/* Bind socket to a new port */ |
u_addrtosockaddr(&s->self_addr,s->self_port,&sas); | u_addrtosockaddr(&tun->self_addr,tun->self_port,&sas); |
if (NgSendMsg(csock, namebuf, NGM_KSOCKET_COOKIE, |
if (NgSendMsg(csock, namebuf, NGM_KSOCKET_COOKIE, |
NGM_KSOCKET_BIND, &sas, sas.ss_len) == -1) { |
NGM_KSOCKET_BIND, &sas, sas.ss_len) == -1) { |
Perror("L2TP: bind"); |
Perror("L2TP: bind"); |
Line 1631 L2tpListen(Link l)
|
Line 1656 L2tpListen(Link l)
|
|
|
/* Setup UDP socket that listens for new connections */ |
/* Setup UDP socket that listens for new connections */ |
if (s->self_addr.family==AF_INET6) { |
if (s->self_addr.family==AF_INET6) { |
s->sock = socket(PF_INET6, SOCK_DGRAM, IPPROTO_UDP); | s->sock = socket(PF_INET6, socktype(SOCK_DGRAM), IPPROTO_UDP); |
} else { |
} else { |
s->sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); | s->sock = socket(PF_INET, socktype(SOCK_DGRAM), IPPROTO_UDP); |
} |
} |
if (s->sock == -1) { |
if (s->sock == -1) { |
Perror("L2TP: socket"); |
Perror("L2TP: socket"); |
Line 1649 L2tpListen(Link l)
|
Line 1674 L2tpListen(Link l)
|
Perror("L2TP: setsockopt"); |
Perror("L2TP: setsockopt"); |
goto fail; |
goto fail; |
} |
} |
|
if (u_addrempty(&s->self_addr)) { |
|
int on = 1; |
|
setsockopt(s->sock, IPPROTO_IP, IP_RECVDSTADDR, &on, sizeof(on)); |
|
} |
u_addrtosockaddr(&s->self_addr, s->self_port, &sa); |
u_addrtosockaddr(&s->self_addr, s->self_port, &sa); |
if (bind(s->sock, (struct sockaddr *)&sa, sa.ss_len) == -1) { |
if (bind(s->sock, (struct sockaddr *)&sa, sa.ss_len) == -1) { |
Perror("L2TP: bind"); |
Perror("L2TP: bind"); |
Line 1722 L2tpNodeUpdate(Link l)
|
Line 1751 L2tpNodeUpdate(Link l)
|
*/ |
*/ |
|
|
static int |
static int |
L2tpSetCommand(Context ctx, int ac, char *av[], void *arg) | L2tpSetCommand(Context ctx, int ac, const char *const av[], const void *arg) |
{ |
{ |
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; |
Line 1802 L2tpSetCommand(Context ctx, int ac, char *av[], void *
|
Line 1831 L2tpSetCommand(Context ctx, int ac, char *av[], void *
|
*/ |
*/ |
|
|
int |
int |
L2tpsStat(Context ctx, int ac, char *av[], void *arg) | L2tpsStat(Context ctx, int ac, const char *const av[], const void *arg) |
{ |
{ |
struct l2tp_tun *tun; |
struct l2tp_tun *tun; |
struct ghash_walk walk; |
struct ghash_walk walk; |
char buf1[64], buf2[64], buf3[64]; |
char buf1[64], buf2[64], buf3[64]; |
|
|
|
(void)ac; |
|
(void)av; |
|
(void)arg; |
|
|
Printf("Active L2TP tunnels:\r\n"); |
Printf("Active L2TP tunnels:\r\n"); |
ghash_walk_init(gL2tpTuns, &walk); |
ghash_walk_init(gL2tpTuns, &walk); |