|
version 1.1.1.2, 2013/07/22 08:44:29
|
version 1.1.1.3, 2016/11/01 09:56:12
|
|
Line 99
|
Line 99
|
| |
|
| #ifdef USE_NG_NETFLOW |
#ifdef USE_NG_NETFLOW |
| static int IfaceInitNetflow(Bund b, char *path, char *hook, char in, char out, int v6); |
static int IfaceInitNetflow(Bund b, char *path, char *hook, char in, char out, int v6); |
| static int IfaceSetupNetflow(Bund b, char in, char out); | static int IfaceSetupNetflow(Bund b, char in, char out, int v6); |
| static void IfaceShutdownNetflow(Bund b, char in, char out); | static void IfaceShutdownNetflow(Bund b, char in, char out, int v6); |
| #endif |
#endif |
| |
|
| #ifdef USE_NG_IPACCT |
#ifdef USE_NG_IPACCT |
|
Line 140
|
Line 140
|
| #ifdef USE_IPFW |
#ifdef USE_IPFW |
| static int IfaceAllocACL (struct acl_pool ***ap, int start, char * ifname, int number); |
static int IfaceAllocACL (struct acl_pool ***ap, int start, char * ifname, int number); |
| static int IfaceFindACL (struct acl_pool *ap, char * ifname, int number); |
static int IfaceFindACL (struct acl_pool *ap, char * ifname, int number); |
| static char * IFaceParseACL (char * src, char * ifname); | static char * IfaceParseACL (char * src, IfaceState iface); |
| #endif |
#endif |
| |
|
| static int IfaceSetName(Bund b, const char * ifname); |
static int IfaceSetName(Bund b, const char * ifname); |
|
Line 197
|
Line 197
|
| static const struct confinfo gConfList[] = { |
static const struct confinfo gConfList[] = { |
| { 0, IFACE_CONF_ONDEMAND, "on-demand" }, |
{ 0, IFACE_CONF_ONDEMAND, "on-demand" }, |
| { 0, IFACE_CONF_PROXY, "proxy-arp" }, |
{ 0, IFACE_CONF_PROXY, "proxy-arp" }, |
| |
{ 0, IFACE_CONF_KEEP_TIMEOUT, "keep-timeout" }, |
| #ifdef USE_NG_TCPMSS |
#ifdef USE_NG_TCPMSS |
| { 0, IFACE_CONF_TCPMSSFIX, "tcpmssfix" }, |
{ 0, IFACE_CONF_TCPMSSFIX, "tcpmssfix" }, |
| #endif |
#endif |
|
Line 230
|
Line 231
|
| |
|
| #ifdef USE_NG_BPF |
#ifdef USE_NG_BPF |
| /* A BPF filter that matches TCP SYN packets */ |
/* A BPF filter that matches TCP SYN packets */ |
| static const struct bpf_insn gTCPSYNProg[] = { | static const struct bpf_insn gTCPSYNProg[] __attribute__((used)) = { |
| /*00*/ BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 9), /* A <- IP protocol */ |
/*00*/ BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 9), /* A <- IP protocol */ |
| /*01*/ BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, IPPROTO_TCP, 0, 6), /* !TCP => 8 */ |
/*01*/ BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, IPPROTO_TCP, 0, 6), /* !TCP => 8 */ |
| /*02*/ BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 6), /* A <- fragmentation offset */ |
/*02*/ BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 6), /* A <- fragmentation offset */ |
|
Line 293 IfaceInit(Bund b)
|
Line 294 IfaceInit(Bund b)
|
| #endif |
#endif |
| Disable(&iface->options, IFACE_CONF_ONDEMAND); |
Disable(&iface->options, IFACE_CONF_ONDEMAND); |
| Disable(&iface->options, IFACE_CONF_PROXY); |
Disable(&iface->options, IFACE_CONF_PROXY); |
| |
Disable(&iface->options, IFACE_CONF_KEEP_TIMEOUT); |
| Disable(&iface->options, IFACE_CONF_TCPMSSFIX); |
Disable(&iface->options, IFACE_CONF_TCPMSSFIX); |
| #ifdef USE_NG_NAT |
#ifdef USE_NG_NAT |
| NatInit(b); |
NatInit(b); |
|
Line 453 IfaceUp(Bund b, int ready)
|
Line 455 IfaceUp(Bund b, int ready)
|
| |
|
| /* Start Session timer */ |
/* Start Session timer */ |
| if (b->params.session_timeout > 0) { |
if (b->params.session_timeout > 0) { |
| session_timeout = b->params.session_timeout; | if (Enabled(&iface->options, IFACE_CONF_KEEP_TIMEOUT)) { |
| | session_timeout = b->params.session_timeout - \ |
| | (iface->last_up - b->last_up); |
| | Log(LG_IFACE2, ("[%s] IFACE: keep session-timeout at: %d seconds", |
| | b->name, session_timeout)); |
| | } else { |
| | session_timeout = b->params.session_timeout; |
| | } |
| } else if (iface->session_timeout > 0) { |
} else if (iface->session_timeout > 0) { |
| session_timeout = iface->session_timeout; |
session_timeout = iface->session_timeout; |
| } |
} |
|
Line 464 IfaceUp(Bund b, int ready)
|
Line 473 IfaceUp(Bund b, int ready)
|
| if (session_timeout > INT_MAX / 1100) { |
if (session_timeout > INT_MAX / 1100) { |
| session_timeout = INT_MAX / 1100; |
session_timeout = INT_MAX / 1100; |
| Log(LG_ERR, ("[%s] IFACE: session-timeout limited to %d seconds", |
Log(LG_ERR, ("[%s] IFACE: session-timeout limited to %d seconds", |
| b->name, session_timeout)); | b->name, session_timeout)); |
| } |
} |
| TimerInit(&iface->sessionTimer, "IfaceSession", |
TimerInit(&iface->sessionTimer, "IfaceSession", |
| session_timeout * SECONDS, IfaceSessionTimeout, b); |
session_timeout * SECONDS, IfaceSessionTimeout, b); |
|
Line 584 IfaceUp(Bund b, int ready)
|
Line 593 IfaceUp(Bund b, int ready)
|
| } |
} |
| acls = b->params.acl_queue; |
acls = b->params.acl_queue; |
| while (acls != NULL) { |
while (acls != NULL) { |
| buf = IFaceParseACL(acls->rule,iface->ifname); | buf = IfaceParseACL(acls->rule, iface); |
| ExecCmd(LG_IFACE2, b->name, "%s queue %d config %s", PATH_IPFW, acls->real_number, buf); |
ExecCmd(LG_IFACE2, b->name, "%s queue %d config %s", PATH_IPFW, acls->real_number, buf); |
| Freee(buf); |
Freee(buf); |
| acls = acls->next; |
acls = acls->next; |
| } |
} |
| acls = b->params.acl_table; |
acls = b->params.acl_table; |
| while (acls != NULL) { |
while (acls != NULL) { |
| |
/* allow both %aX and `peer_addr` macros */ |
| |
buf = IfaceParseACL(acls->rule, iface); |
| |
strcpy(acls->rule, buf); |
| |
Freee(buf); |
| acl = Mdup(MB_IPFW, acls, sizeof(struct acl) + strlen(acls->rule)); |
acl = Mdup(MB_IPFW, acls, sizeof(struct acl) + strlen(acls->rule)); |
| acl->next = iface->tables; |
acl->next = iface->tables; |
| iface->tables = acl; |
iface->tables = acl; |
| ExecCmd(LG_IFACE2, b->name, "%s table %d add %s", PATH_IPFW, acls->real_number, acls->rule); | if (strncmp(acls->rule, "peer_addr", 9) == 0) { |
| | char hisaddr[20]; |
| | ExecCmd(LG_IFACE2, b->name, "%s table %d add %s", |
| | PATH_IPFW, acls->real_number, |
| | u_addrtoa(&iface->peer_addr, hisaddr, sizeof(hisaddr))); |
| | } else { |
| | ExecCmd(LG_IFACE2, b->name, "%s table %d add %s", PATH_IPFW, acls->real_number, acls->rule); |
| | } |
| acls = acls->next; |
acls = acls->next; |
| }; |
}; |
| acls = b->params.acl_rule; |
acls = b->params.acl_rule; |
| while (acls != NULL) { |
while (acls != NULL) { |
| buf = IFaceParseACL(acls->rule, iface->ifname); | buf = IfaceParseACL(acls->rule, iface); |
| ExecCmd(LG_IFACE2, b->name, "%s add %d %s via %s", PATH_IPFW, acls->real_number, buf, iface->ifname); |
ExecCmd(LG_IFACE2, b->name, "%s add %d %s via %s", PATH_IPFW, acls->real_number, buf, iface->ifname); |
| Freee(buf); |
Freee(buf); |
| acls = acls->next; |
acls = acls->next; |
|
Line 671 IfaceDown(Bund b)
|
Line 691 IfaceDown(Bund b)
|
| }; |
}; |
| acl = iface->tables; |
acl = iface->tables; |
| while (acl != NULL) { |
while (acl != NULL) { |
| ExecCmd(LG_IFACE2, b->name, "%s table %d delete %s", | if (strncmp(acl->rule, "peer_addr", 9) == 0) { |
| PATH_IPFW, acl->real_number, acl->rule); | char hisaddr[20]; |
| | ExecCmd(LG_IFACE2, b->name, "%s table %d delete %s", |
| | PATH_IPFW, acl->real_number, |
| | u_addrtoa(&iface->peer_addr, hisaddr, sizeof(hisaddr))); |
| | } else { |
| | ExecCmd(LG_IFACE2, b->name, "%s table %d delete %s", |
| | PATH_IPFW, acl->real_number, acl->rule); |
| | } |
| aclnext = acl->next; |
aclnext = acl->next; |
| Freee(acl); |
Freee(acl); |
| acl = aclnext; |
acl = aclnext; |
|
Line 840 IfaceFindACL (struct acl_pool *ap, char * ifname, int
|
Line 867 IfaceFindACL (struct acl_pool *ap, char * ifname, int
|
| } |
} |
| |
|
| /* |
/* |
| * IFaceParseACL () | * IfaceParseACL () |
| * |
* |
| * Parces ACL and replaces %r, %p and %q macroses | * Parses ACL and replaces %r, %p and %q macroses |
| * by the real numbers of rules, queues and pipes. |
* by the real numbers of rules, queues and pipes. |
| |
* |
| |
* Also replaces %a1 and a2 with the remote(peer) |
| |
* or local(self) IP address respectively. |
| */ |
*/ |
| |
|
| static char * |
static char * |
| IFaceParseACL (char * src, char * ifname) | IfaceParseACL (char * src, IfaceState iface) |
| { |
{ |
| char *buf,*buf1; |
char *buf,*buf1; |
| char *begin,*param,*end; |
char *begin,*param,*end; |
| char t; |
char t; |
| int num,real_number; |
int num,real_number; |
| struct acl_pool *ap; |
struct acl_pool *ap; |
| |
char hisaddr[20]; |
| |
int ipmode = 0; /* 0 - normal macro, 1 - IP address macro */ |
| |
|
| buf = Malloc(MB_IPFW, ACL_LEN); |
buf = Malloc(MB_IPFW, ACL_LEN); |
| buf1 = Malloc(MB_IPFW, ACL_LEN); |
buf1 = Malloc(MB_IPFW, ACL_LEN); |
|
Line 878 IFaceParseACL (char * src, char * ifname)
|
Line 910 IFaceParseACL (char * src, char * ifname)
|
| case 't': |
case 't': |
| ap = table_pool; |
ap = table_pool; |
| break; |
break; |
| |
case 'a': |
| |
ipmode = 1; |
| |
if (num == 1) |
| |
u_addrtoa(&iface->peer_addr, hisaddr, sizeof(hisaddr)); |
| |
else if (num == 2) |
| |
u_rangetoa(&iface->self_addr, hisaddr, sizeof(hisaddr)); |
| |
else |
| |
ipmode = 0; |
| |
ap = NULL; |
| |
break; |
| default: |
default: |
| ap = NULL; |
ap = NULL; |
| }; |
}; |
| real_number = IfaceFindACL(ap,ifname,num); | if (ipmode) |
| if (end != NULL) { | { |
| snprintf(buf1, ACL_LEN, "%s%d %s", begin, real_number, end); | if (end != NULL) |
| } else { | snprintf(buf1, ACL_LEN, "%s%s %s", begin, hisaddr, end); |
| snprintf(buf1, ACL_LEN, "%s%d", begin, real_number); | else |
| }; | snprintf(buf1, ACL_LEN, "%s%s", begin, hisaddr); |
| | ipmode = 0; |
| | } |
| | else |
| | { |
| | real_number = IfaceFindACL(ap, iface->ifname, num); |
| | if (end != NULL) |
| | snprintf(buf1, ACL_LEN, "%s%d %s", begin, real_number, end); |
| | else |
| | snprintf(buf1, ACL_LEN, "%s%d", begin, real_number); |
| | } |
| strlcpy(buf, buf1, ACL_LEN); |
strlcpy(buf, buf1, ACL_LEN); |
| }; |
}; |
| }; |
}; |
|
Line 940 IfaceIpIfaceUp(Bund b, int ready)
|
Line 992 IfaceIpIfaceUp(Bund b, int ready)
|
| /* Proxy ARP for peer if desired and peer's address is known */ |
/* Proxy ARP for peer if desired and peer's address is known */ |
| u_addrclear(&iface->proxy_addr); |
u_addrclear(&iface->proxy_addr); |
| if (Enabled(&iface->options, IFACE_CONF_PROXY)) { |
if (Enabled(&iface->options, IFACE_CONF_PROXY)) { |
| |
u_addrtoa(&iface->peer_addr,hisaddr,sizeof(hisaddr)); |
| if (u_addrempty(&iface->peer_addr)) { |
if (u_addrempty(&iface->peer_addr)) { |
| Log(LG_IFACE, | Log(LG_IFACE, ("[%s] IFACE: Can't proxy arp for %s", |
| ("[%s] IFACE: Can't proxy arp for %s", | b->name, hisaddr)); |
| b->name, u_addrtoa(&iface->peer_addr,hisaddr,sizeof(hisaddr)))); | |
| } else if (GetEther(&iface->peer_addr, &hwa) < 0) { |
} else if (GetEther(&iface->peer_addr, &hwa) < 0) { |
| Log(LG_IFACE, | Log(LG_IFACE, ("[%s] IFACE: No interface to proxy arp on for %s", |
| ("[%s] IFACE: No interface to proxy arp on for %s", | b->name, hisaddr)); |
| b->name, u_addrtoa(&iface->peer_addr,hisaddr,sizeof(hisaddr)))); | |
| } else { |
} else { |
| ether = (u_char *) LLADDR(&hwa); |
ether = (u_char *) LLADDR(&hwa); |
| if (ExecCmdNosh(LG_IFACE2, b->name, |
if (ExecCmdNosh(LG_IFACE2, b->name, |
| "%s -S %s %x:%x:%x:%x:%x:%x pub", |
"%s -S %s %x:%x:%x:%x:%x:%x pub", |
| PATH_ARP, u_addrtoa(&iface->peer_addr,hisaddr,sizeof(hisaddr)), | PATH_ARP, hisaddr, |
| ether[0], ether[1], ether[2], |
ether[0], ether[1], ether[2], |
| ether[3], ether[4], ether[5]) == 0) |
ether[3], ether[4], ether[5]) == 0) |
| iface->proxy_addr = iface->peer_addr; | iface->proxy_addr = iface->peer_addr; |
| } |
} |
| } |
} |
| |
|
|
Line 993 IfaceIpIfaceUp(Bund b, int ready)
|
Line 1044 IfaceIpIfaceUp(Bund b, int ready)
|
| else |
else |
| ns2buf[0] = '\0'; |
ns2buf[0] = '\0'; |
| |
|
| res = ExecCmd(LG_IFACE2, b->name, "%s %s inet %s %s '%s' '%s' '%s' '%s'", | res = ExecCmd(LG_IFACE2, b->name, "%s %s inet %s %s '%s' '%s' '%s' '%s' '%s'", |
| iface->up_script, iface->ifname, u_rangetoa(&iface->self_addr,selfbuf, sizeof(selfbuf)), | iface->up_script, iface->ifname, |
| | u_rangetoa(&iface->self_addr,selfbuf, sizeof(selfbuf)), |
| u_addrtoa(&iface->peer_addr, peerbuf, sizeof(peerbuf)), |
u_addrtoa(&iface->peer_addr, peerbuf, sizeof(peerbuf)), |
| *b->params.authname ? b->params.authname : "-", |
*b->params.authname ? b->params.authname : "-", |
| ns1buf, ns2buf, *b->params.peeraddr ? b->params.peeraddr : "-"); | ns1buf, ns2buf, *b->params.peeraddr ? b->params.peeraddr : "-", |
| | b->params.filter_id ? b->params.filter_id : "-"); |
| if (res != 0) { |
if (res != 0) { |
| FsmFailure(&b->ipcp.fsm, FAIL_NEGOT_FAILURE); |
FsmFailure(&b->ipcp.fsm, FAIL_NEGOT_FAILURE); |
| return (-1); |
return (-1); |
|
Line 1023 IfaceIpIfaceDown(Bund b)
|
Line 1076 IfaceIpIfaceDown(Bund b)
|
| if (*iface->down_script) { |
if (*iface->down_script) { |
| char selfbuf[40],peerbuf[40]; |
char selfbuf[40],peerbuf[40]; |
| |
|
| ExecCmd(LG_IFACE2, b->name, "%s %s inet %s %s '%s' '%s'", | ExecCmd(LG_IFACE2, b->name, "%s %s inet %s %s '%s' '%s' '%s'", |
| iface->down_script, iface->ifname, u_rangetoa(&iface->self_addr,selfbuf, sizeof(selfbuf)), | iface->down_script, iface->ifname, |
| | u_rangetoa(&iface->self_addr,selfbuf, sizeof(selfbuf)), |
| u_addrtoa(&iface->peer_addr, peerbuf, sizeof(peerbuf)), |
u_addrtoa(&iface->peer_addr, peerbuf, sizeof(peerbuf)), |
| *b->params.authname ? b->params.authname : "-", |
*b->params.authname ? b->params.authname : "-", |
| *b->params.peeraddr ? b->params.peeraddr : "-"); | *b->params.peeraddr ? b->params.peeraddr : "-", |
| | b->params.filter_id ? b->params.filter_id : "-"); |
| } |
} |
| |
|
| /* Delete dynamic routes */ |
/* Delete dynamic routes */ |
|
Line 1080 IfaceIpv6IfaceUp(Bund b, int ready)
|
Line 1135 IfaceIpv6IfaceUp(Bund b, int ready)
|
| iface->self_ipv6_addr.u.ip6.__u6_addr.__u6_addr16[1] = 0x0000; |
iface->self_ipv6_addr.u.ip6.__u6_addr.__u6_addr16[1] = 0x0000; |
| iface->self_ipv6_addr.u.ip6.__u6_addr.__u6_addr16[2] = 0x0000; |
iface->self_ipv6_addr.u.ip6.__u6_addr.__u6_addr16[2] = 0x0000; |
| iface->self_ipv6_addr.u.ip6.__u6_addr.__u6_addr16[3] = 0x0000; |
iface->self_ipv6_addr.u.ip6.__u6_addr.__u6_addr16[3] = 0x0000; |
| iface->self_ipv6_addr.u.ip6.__u6_addr.__u6_addr16[4] = ((u_short*)b->ipv6cp.myintid)[0]; | bcopy(b->ipv6cp.myintid, &iface->self_ipv6_addr.u.ip6.__u6_addr.__u6_addr16[4], sizeof(b->ipv6cp.myintid)); |
| iface->self_ipv6_addr.u.ip6.__u6_addr.__u6_addr16[5] = ((u_short*)b->ipv6cp.myintid)[1]; | bcopy(&iface->self_ipv6_addr.u.ip6, &b->ipv6cp.want_addr, sizeof(struct in6_addr)); |
| iface->self_ipv6_addr.u.ip6.__u6_addr.__u6_addr16[6] = ((u_short*)b->ipv6cp.myintid)[2]; | |
| iface->self_ipv6_addr.u.ip6.__u6_addr.__u6_addr16[7] = ((u_short*)b->ipv6cp.myintid)[3]; | |
| } else { |
} else { |
| u_addrcopy(&iface->conf.self_ipv6_addr, &iface->self_ipv6_addr); |
u_addrcopy(&iface->conf.self_ipv6_addr, &iface->self_ipv6_addr); |
| } |
} |
|
Line 1093 IfaceIpv6IfaceUp(Bund b, int ready)
|
Line 1146 IfaceIpv6IfaceUp(Bund b, int ready)
|
| iface->peer_ipv6_addr.u.ip6.__u6_addr.__u6_addr16[1] = 0x0000; |
iface->peer_ipv6_addr.u.ip6.__u6_addr.__u6_addr16[1] = 0x0000; |
| iface->peer_ipv6_addr.u.ip6.__u6_addr.__u6_addr16[2] = 0x0000; |
iface->peer_ipv6_addr.u.ip6.__u6_addr.__u6_addr16[2] = 0x0000; |
| iface->peer_ipv6_addr.u.ip6.__u6_addr.__u6_addr16[3] = 0x0000; |
iface->peer_ipv6_addr.u.ip6.__u6_addr.__u6_addr16[3] = 0x0000; |
| iface->peer_ipv6_addr.u.ip6.__u6_addr.__u6_addr16[4] = ((u_short*)b->ipv6cp.hisintid)[0]; | bcopy(b->ipv6cp.hisintid, &iface->peer_ipv6_addr.u.ip6.__u6_addr.__u6_addr16[4], sizeof(b->ipv6cp.hisintid)); |
| iface->peer_ipv6_addr.u.ip6.__u6_addr.__u6_addr16[5] = ((u_short*)b->ipv6cp.hisintid)[1]; | bcopy(&iface->peer_ipv6_addr.u.ip6, &b->ipv6cp.peer_addr, sizeof(struct in6_addr)); |
| iface->peer_ipv6_addr.u.ip6.__u6_addr.__u6_addr16[6] = ((u_short*)b->ipv6cp.hisintid)[2]; | |
| iface->peer_ipv6_addr.u.ip6.__u6_addr.__u6_addr16[7] = ((u_short*)b->ipv6cp.hisintid)[3]; | |
| } else { |
} else { |
| u_addrcopy(&iface->conf.peer_ipv6_addr, &iface->peer_ipv6_addr); |
u_addrcopy(&iface->conf.peer_ipv6_addr, &iface->peer_ipv6_addr); |
| } |
} |
|
Line 1137 IfaceIpv6IfaceUp(Bund b, int ready)
|
Line 1188 IfaceIpv6IfaceUp(Bund b, int ready)
|
| char selfbuf[48],peerbuf[48]; |
char selfbuf[48],peerbuf[48]; |
| int res; |
int res; |
| |
|
| res = ExecCmd(LG_IFACE2, b->name, "%s %s inet6 %s%%%s %s%%%s '%s' '%s'", | res = ExecCmd(LG_IFACE2, b->name, "%s %s inet6 %s%%%s %s%%%s '%s' '%s' '%s'", |
| iface->up_script, iface->ifname, |
iface->up_script, iface->ifname, |
| u_addrtoa(&iface->self_ipv6_addr, selfbuf, sizeof(selfbuf)), iface->ifname, |
u_addrtoa(&iface->self_ipv6_addr, selfbuf, sizeof(selfbuf)), iface->ifname, |
| u_addrtoa(&iface->peer_ipv6_addr, peerbuf, sizeof(peerbuf)), iface->ifname, |
u_addrtoa(&iface->peer_ipv6_addr, peerbuf, sizeof(peerbuf)), iface->ifname, |
| *b->params.authname ? b->params.authname : "-", |
*b->params.authname ? b->params.authname : "-", |
| *b->params.peeraddr ? b->params.peeraddr : "-"); | *b->params.peeraddr ? b->params.peeraddr : "-", |
| | b->params.filter_id ? b->params.filter_id : "-"); |
| if (res != 0) { |
if (res != 0) { |
| FsmFailure(&b->ipv6cp.fsm, FAIL_NEGOT_FAILURE); |
FsmFailure(&b->ipv6cp.fsm, FAIL_NEGOT_FAILURE); |
| return (-1); |
return (-1); |
|
Line 1169 IfaceIpv6IfaceDown(Bund b)
|
Line 1221 IfaceIpv6IfaceDown(Bund b)
|
| if (*iface->down_script) { |
if (*iface->down_script) { |
| char selfbuf[48],peerbuf[48]; |
char selfbuf[48],peerbuf[48]; |
| |
|
| ExecCmd(LG_IFACE2, b->name, "%s %s inet6 %s%%%s %s%%%s '%s' '%s'", | ExecCmd(LG_IFACE2, b->name, "%s %s inet6 %s%%%s %s%%%s '%s' '%s' '%s'", |
| iface->down_script, iface->ifname, |
iface->down_script, iface->ifname, |
| u_addrtoa(&iface->self_ipv6_addr, selfbuf, sizeof(selfbuf)), iface->ifname, |
u_addrtoa(&iface->self_ipv6_addr, selfbuf, sizeof(selfbuf)), iface->ifname, |
| u_addrtoa(&iface->peer_ipv6_addr, peerbuf, sizeof(peerbuf)), iface->ifname, |
u_addrtoa(&iface->peer_ipv6_addr, peerbuf, sizeof(peerbuf)), iface->ifname, |
| *b->params.authname ? b->params.authname : "-", |
*b->params.authname ? b->params.authname : "-", |
| *b->params.peeraddr ? b->params.peeraddr : "-"); | *b->params.peeraddr ? b->params.peeraddr : "-", |
| | b->params.filter_id ? b->params.filter_id : "-"); |
| } |
} |
| |
|
| /* Delete dynamic routes */ |
/* Delete dynamic routes */ |
|
Line 1843 add_scope(struct sockaddr *sa, int ifindex)
|
Line 1896 add_scope(struct sockaddr *sa, int ifindex)
|
| if (!IN6_IS_ADDR_LINKLOCAL(&sa6->sin6_addr) && |
if (!IN6_IS_ADDR_LINKLOCAL(&sa6->sin6_addr) && |
| !IN6_IS_ADDR_MC_LINKLOCAL(&sa6->sin6_addr)) |
!IN6_IS_ADDR_MC_LINKLOCAL(&sa6->sin6_addr)) |
| return; |
return; |
| if (*(u_int16_t *)&sa6->sin6_addr.s6_addr[2] != 0) | if (sa6->sin6_addr.__u6_addr.__u6_addr16[1] != 0) |
| return; |
return; |
| *(u_int16_t *)&sa6->sin6_addr.s6_addr[2] = htons(ifindex); | sa6->sin6_addr.__u6_addr.__u6_addr16[1] = htons(ifindex); |
| } |
} |
| #endif |
#endif |
| |
|
|
Line 2090 IfaceNgIpInit(Bund b, int ready)
|
Line 2143 IfaceNgIpInit(Bund b, int ready)
|
| snprintf(hook, sizeof(hook), "4%d", b->id); |
snprintf(hook, sizeof(hook), "4%d", b->id); |
| |
|
| } else { |
} else { |
| |
|
| snprintf(path, sizeof(path), "[%x]:", b->nodeID); |
snprintf(path, sizeof(path), "[%x]:", b->nodeID); |
| strcpy(hook, NG_PPP_HOOK_INET); |
strcpy(hook, NG_PPP_HOOK_INET); |
| |
|
|
Line 2180 IfaceNgIpInit(Bund b, int ready)
|
Line 2232 IfaceNgIpInit(Bund b, int ready)
|
| #ifdef USE_NG_NETFLOW |
#ifdef USE_NG_NETFLOW |
| #ifdef NG_NETFLOW_CONF_INGRESS |
#ifdef NG_NETFLOW_CONF_INGRESS |
| if (b->iface.nfin_up || b->iface.nfout_up) |
if (b->iface.nfin_up || b->iface.nfout_up) |
| IfaceSetupNetflow(b, b->iface.nfin_up, b->iface.nfout_up); | IfaceSetupNetflow(b, b->iface.nfin_up, b->iface.nfout_up, 0); |
| #else /* NG_NETFLOW_CONF_INGRESS */ |
#else /* NG_NETFLOW_CONF_INGRESS */ |
| if (b->iface.nfin_up) |
if (b->iface.nfin_up) |
| IfaceSetupNetflow(b, 1, 0); | IfaceSetupNetflow(b, 1, 0, 0); |
| |
|
| if (b->iface.nfout_up) |
if (b->iface.nfout_up) |
| IfaceSetupNetflow(b, 0, 1); | IfaceSetupNetflow(b, 0, 1, 0); |
| #endif /* NG_NETFLOW_CONF_INGRESS */ |
#endif /* NG_NETFLOW_CONF_INGRESS */ |
| #endif /* USE_NG_NETFLOW */ |
#endif /* USE_NG_NETFLOW */ |
| } |
} |
|
Line 2230 IfaceNgIpShutdown(Bund b)
|
Line 2282 IfaceNgIpShutdown(Bund b)
|
| #ifdef USE_NG_NETFLOW |
#ifdef USE_NG_NETFLOW |
| #ifdef NG_NETFLOW_CONF_INGRESS |
#ifdef NG_NETFLOW_CONF_INGRESS |
| if (b->iface.nfin_up || b->iface.nfout_up) |
if (b->iface.nfin_up || b->iface.nfout_up) |
| IfaceShutdownNetflow(b, b->iface.nfin_up, b->iface.nfout_up); | IfaceShutdownNetflow(b, b->iface.nfin_up, b->iface.nfout_up, 0); |
| b->iface.nfin_up = 0; |
b->iface.nfin_up = 0; |
| b->iface.nfout_up = 0; |
b->iface.nfout_up = 0; |
| #else /* NG_NETFLOW_CONF_INGRESS */ |
#else /* NG_NETFLOW_CONF_INGRESS */ |
| if (b->iface.nfin_up) |
if (b->iface.nfin_up) |
| IfaceShutdownNetflow(b, 1, 0); | IfaceShutdownNetflow(b, 1, 0, 0); |
| b->iface.nfin_up = 0; |
b->iface.nfin_up = 0; |
| if (b->iface.nfout_up) |
if (b->iface.nfout_up) |
| IfaceShutdownNetflow(b, 0, 1); | IfaceShutdownNetflow(b, 0, 1, 0); |
| b->iface.nfout_up = 0; |
b->iface.nfout_up = 0; |
| #endif /* NG_NETFLOW_CONF_INGRESS */ |
#endif /* NG_NETFLOW_CONF_INGRESS */ |
| #endif |
#endif |
|
Line 2299 IfaceNgIpv6Init(Bund b, int ready)
|
Line 2351 IfaceNgIpv6Init(Bund b, int ready)
|
| } |
} |
| #else /* NG_NETFLOW_CONF_INGRESS */ |
#else /* NG_NETFLOW_CONF_INGRESS */ |
| /* Connect a netflow node if configured */ |
/* Connect a netflow node if configured */ |
| if (Enabled(&b->iface.options, IFACE_CONF_NETFLOW_IN, 1)) { | if (Enabled(&b->iface.options, IFACE_CONF_NETFLOW_IN)) { |
| if (IfaceInitNetflow(b, path, hook, 1, 0)) | if (IfaceInitNetflow(b, path, hook, 1, 0, 1)) |
| goto fail; |
goto fail; |
| b->iface.nfin_up = 1; |
b->iface.nfin_up = 1; |
| } |
} |
|
Line 2314 IfaceNgIpv6Init(Bund b, int ready)
|
Line 2366 IfaceNgIpv6Init(Bund b, int ready)
|
| #endif /* USE_NG_NETFLOW */ |
#endif /* USE_NG_NETFLOW */ |
| } |
} |
| |
|
| |
#ifdef USE_NG_BPF |
| |
if (IfaceInitLimits(b, path, hook)) |
| |
goto fail; |
| |
#endif |
| |
|
| /* Connect graph to the iface node. */ |
/* Connect graph to the iface node. */ |
| strcpy(cn.ourhook, hook); |
strcpy(cn.ourhook, hook); |
| snprintf(cn.path, sizeof(cn.path), "%s:", b->iface.ngname); |
snprintf(cn.path, sizeof(cn.path), "%s:", b->iface.ngname); |
|
Line 2329 IfaceNgIpv6Init(Bund b, int ready)
|
Line 2386 IfaceNgIpv6Init(Bund b, int ready)
|
| #ifdef USE_NG_NETFLOW |
#ifdef USE_NG_NETFLOW |
| #ifdef NG_NETFLOW_CONF_INGRESS |
#ifdef NG_NETFLOW_CONF_INGRESS |
| if (b->iface.nfin_up || b->iface.nfout_up) |
if (b->iface.nfin_up || b->iface.nfout_up) |
| IfaceSetupNetflow(b, b->iface.nfin_up, b->iface.nfout_up); | IfaceSetupNetflow(b, b->iface.nfin_up, b->iface.nfout_up, 1); |
| #else /* NG_NETFLOW_CONF_INGRESS */ |
#else /* NG_NETFLOW_CONF_INGRESS */ |
| if (b->iface.nfin_up) |
if (b->iface.nfin_up) |
| IfaceSetupNetflow(b, 1, 0); | IfaceSetupNetflow(b, 1, 0, 1); |
| |
|
| if (b->iface.nfout_up) |
if (b->iface.nfout_up) |
| IfaceSetupNetflow(b, 0, 1); | IfaceSetupNetflow(b, 0, 1, 1); |
| #endif /* NG_NETFLOW_CONF_INGRESS */ |
#endif /* NG_NETFLOW_CONF_INGRESS */ |
| #endif /* USE_NG_NETFLOW */ |
#endif /* USE_NG_NETFLOW */ |
| } |
} |
| |
|
| |
#ifdef USE_NG_BPF |
| |
IfaceSetupLimits(b); |
| |
#endif |
| |
|
| /* OK */ |
/* OK */ |
| return(0); |
return(0); |
| |
|
|
Line 2356 IfaceNgIpv6Shutdown(Bund b)
|
Line 2417 IfaceNgIpv6Shutdown(Bund b)
|
| { |
{ |
| char path[NG_PATHSIZ]; |
char path[NG_PATHSIZ]; |
| |
|
| |
#ifdef USE_NG_BPF |
| |
IfaceShutdownLimits(b); /* Limits must shutdown first to save final stats. */ |
| |
#endif |
| if (b->iface.tee6_up) |
if (b->iface.tee6_up) |
| IfaceShutdownTee(b, 1); |
IfaceShutdownTee(b, 1); |
| b->iface.tee6_up = 0; |
b->iface.tee6_up = 0; |
| #ifdef USE_NG_NETFLOW |
#ifdef USE_NG_NETFLOW |
| #ifdef NG_NETFLOW_CONF_INGRESS |
#ifdef NG_NETFLOW_CONF_INGRESS |
| if (b->iface.nfin_up || b->iface.nfout_up) |
if (b->iface.nfin_up || b->iface.nfout_up) |
| IfaceShutdownNetflow(b, b->iface.nfin_up, b->iface.nfout_up); | IfaceShutdownNetflow(b, b->iface.nfin_up, b->iface.nfout_up, 1); |
| b->iface.nfin_up = 0; |
b->iface.nfin_up = 0; |
| b->iface.nfout_up = 0; |
b->iface.nfout_up = 0; |
| #else /* NG_NETFLOW_CONF_INGRESS */ |
#else /* NG_NETFLOW_CONF_INGRESS */ |
| if (b->iface.nfin_up) |
if (b->iface.nfin_up) |
| IfaceShutdownNetflow(b, 1, 0); | IfaceShutdownNetflow(b, 1, 0, 1); |
| b->iface.nfin_up = 0; |
b->iface.nfin_up = 0; |
| if (b->iface.nfout_up) |
if (b->iface.nfout_up) |
| IfaceShutdownNetflow(b, 0, 1); | IfaceShutdownNetflow(b, 0, 1, 1); |
| b->iface.nfout_up = 0; |
b->iface.nfout_up = 0; |
| #endif /* NG_NETFLOW_CONF_INGRESS */ |
#endif /* NG_NETFLOW_CONF_INGRESS */ |
| #endif |
#endif |
|
Line 2469 IfaceSetupNAT(Bund b)
|
Line 2533 IfaceSetupNAT(Bund b)
|
| uint32_t *const nat_id = (uint32_t *)(void *)u.reply.data; |
uint32_t *const nat_id = (uint32_t *)(void *)u.reply.data; |
| #endif |
#endif |
| |
|
| |
snprintf(path, sizeof(path), "mpd%d-%s-nat:", gPid, b->name); |
| if (u_addrempty(&nat->alias_addr)) { |
if (u_addrempty(&nat->alias_addr)) { |
| snprintf(path, sizeof(path), "mpd%d-%s-nat:", gPid, b->name); |
|
| if (NgSendMsg(gLinksCsock, path, |
if (NgSendMsg(gLinksCsock, path, |
| NGM_NAT_COOKIE, NGM_NAT_SET_IPADDR, |
NGM_NAT_COOKIE, NGM_NAT_SET_IPADDR, |
| &b->iface.self_addr.addr.u.ip4, |
&b->iface.self_addr.addr.u.ip4, |
|
Line 2705 IfaceInitNetflow(Bund b, char *path, char *hook, char
|
Line 2769 IfaceInitNetflow(Bund b, char *path, char *hook, char
|
| int nif; |
int nif; |
| |
|
| #ifdef NG_NETFLOW_CONF_INGRESS |
#ifdef NG_NETFLOW_CONF_INGRESS |
| nif = gNetflowIface + b->id; | nif = gNetflowIface + b->id*2; |
| #else |
#else |
| nif = gNetflowIface + b->id*2 + out; | nif = gNetflowIface + b->id*4 + out*2; |
| #endif |
#endif |
| |
nif += v6 ? 1 : 0; |
| |
|
| Log(LG_IFACE2, ("[%s] IFACE: Connecting netflow%s (%s)", |
Log(LG_IFACE2, ("[%s] IFACE: Connecting netflow%s (%s)", |
| b->name, v6?"6":"", out?"out":"in")); |
b->name, v6?"6":"", out?"out":"in")); |
|
Line 2754 IfaceInitNetflow(Bund b, char *path, char *hook, char
|
Line 2819 IfaceInitNetflow(Bund b, char *path, char *hook, char
|
| } |
} |
| |
|
| static int |
static int |
| IfaceSetupNetflow(Bund b, char in, char out) | IfaceSetupNetflow(Bund b, char in, char out, int v6) |
| { |
{ |
| char path[NG_PATHSIZ]; |
char path[NG_PATHSIZ]; |
| struct ng_netflow_setdlt nf_setdlt; |
struct ng_netflow_setdlt nf_setdlt; |
|
Line 2765 IfaceSetupNetflow(Bund b, char in, char out)
|
Line 2830 IfaceSetupNetflow(Bund b, char in, char out)
|
| int nif; |
int nif; |
| |
|
| #ifdef NG_NETFLOW_CONF_INGRESS |
#ifdef NG_NETFLOW_CONF_INGRESS |
| nif = gNetflowIface + b->id; | nif = gNetflowIface + b->id*2; |
| #else |
#else |
| nif = gNetflowIface + b->id*2 + out; | nif = gNetflowIface + b->id*4 + out*2; |
| #endif |
#endif |
| | nif += v6 ? 1 : 0; |
| | |
| /* Configure data link type and interface index. */ |
/* Configure data link type and interface index. */ |
| snprintf(path, sizeof(path), "[%x]:", gNetflowNodeID); |
snprintf(path, sizeof(path), "[%x]:", gNetflowNodeID); |
| nf_setdlt.iface = nif; |
nf_setdlt.iface = nif; |
|
Line 2811 fail:
|
Line 2877 fail:
|
| } |
} |
| |
|
| static void |
static void |
| IfaceShutdownNetflow(Bund b, char in, char out) | IfaceShutdownNetflow(Bund b, char in, char out, int v6) |
| { |
{ |
| char path[NG_PATHSIZ]; |
char path[NG_PATHSIZ]; |
| char hook[NG_HOOKSIZ]; |
char hook[NG_HOOKSIZ]; |
| int nif; |
int nif; |
| |
|
| #ifdef NG_NETFLOW_CONF_INGRESS |
#ifdef NG_NETFLOW_CONF_INGRESS |
| nif = gNetflowIface + b->id; | nif = gNetflowIface + b->id*2; |
| #else |
#else |
| nif = gNetflowIface + b->id*2 + out; | nif = gNetflowIface + b->id*4 + out*2; |
| #endif |
#endif |
| |
nif += v6 ? 1 : 0; |
| |
|
| snprintf(path, NG_PATHSIZ, "[%x]:", gNetflowNodeID); |
snprintf(path, NG_PATHSIZ, "[%x]:", gNetflowNodeID); |
| snprintf(hook, NG_HOOKSIZ, "%s%d", NG_NETFLOW_HOOK_DATA, nif); |
snprintf(hook, NG_HOOKSIZ, "%s%d", NG_NETFLOW_HOOK_DATA, nif); |
|
Line 3618 IfaceSetName(Bund b, const char * ifname)
|
Line 3685 IfaceSetName(Bund b, const char * ifname)
|
| b->name, iface->ifname, ifname)); |
b->name, iface->ifname, ifname)); |
| |
|
| if (ioctl(s, SIOCSIFNAME, (caddr_t)&ifr) < 0) { |
if (ioctl(s, SIOCSIFNAME, (caddr_t)&ifr) < 0) { |
| Perror("[%s] IFACE: ioctl(%s, SIOCSIFNAME)", b->name, iface->ifname); | if (errno != EEXIST) { |
| close(s); | Perror("[%s] IFACE: ioctl(%s, SIOCSIFNAME)", b->name, iface->ifname); |
| return(-1); | close(s); |
| | return(-1); |
| | } |
| } |
} |
| |
|
| close(s); |
close(s); |
|
Line 3645 IfaceSetName(Bund b, const char * ifname)
|
Line 3714 IfaceSetName(Bund b, const char * ifname)
|
| * %I for interface name; |
* %I for interface name; |
| * %l for name of bundle's first link |
* %l for name of bundle's first link |
| * %M for peer MAC address of bundle's first link |
* %M for peer MAC address of bundle's first link |
| |
* %o for local outer ("physical") address of bundle's first link |
| |
* %O for peer outer ("physical") address of bundle's first link |
| |
* %P for peer outer ("physical") port of bundle's first link |
| * %S for interface status (DoD/UP/DOWN) |
* %S for interface status (DoD/UP/DOWN) |
| * %t for type of bundle's first link (pppoe, pptp, l2tp etc.) |
* %t for type of bundle's first link (pppoe, pptp, l2tp etc.) |
| * %u for self auth name (or dash if self auth name not used) |
* %u for self auth name (or dash if self auth name not used) |
|
Line 3748 IfaceSetDescr(Bund b, const char * template)
|
Line 3820 IfaceSetDescr(Bund b, const char * template)
|
| /* peer address */ |
/* peer address */ |
| case 'A': |
case 'A': |
| { |
{ |
| u_addrtoa (&iface->peer_addr, buf, sizeof(buf)); | u_addrtoa(&iface->peer_addr, buf, sizeof(buf)); |
| DST_COPY(buf); |
DST_COPY(buf); |
| } |
} |
| break; |
break; |
| /* interface index */ |
/* interface index */ |
| case 'i': |
case 'i': |
| { |
{ |
| snprintf (buf, sizeof(buf), "%u", iface->ifindex); | snprintf(buf, sizeof(buf), "%u", iface->ifindex); |
| DST_COPY(buf); |
DST_COPY(buf); |
| } |
} |
| break; |
break; |
|
Line 3767 IfaceSetDescr(Bund b, const char * template)
|
Line 3839 IfaceSetDescr(Bund b, const char * template)
|
| case 'l': |
case 'l': |
| DST_COPY(b->links[0] ? b->links[0]->name : NULL); |
DST_COPY(b->links[0] ? b->links[0]->name : NULL); |
| break; |
break; |
| |
/* peer MAC address */ |
| case 'M': |
case 'M': |
| if(b->links[0]) { | if (b->links[0]) { |
| PhysType const pt = b->links[0]->type; |
PhysType const pt = b->links[0]->type; |
| if (pt && pt->peermacaddr) { |
if (pt && pt->peermacaddr) { |
| (*pt->peermacaddr)(b->links[0], buf, sizeof(buf)); | (*pt->peermacaddr)(b->links[0], buf, sizeof(buf)); |
| DST_COPY(buf); | DST_COPY(buf); |
| } else { |
} else { |
| DST_COPY("-"); |
DST_COPY("-"); |
| } |
} |
| |
} else { |
| |
DST_COPY("-"); |
| |
} |
| |
break; |
| |
/* local "physycal" address */ |
| |
case 'o': |
| |
if (b->links[0] && PhysGetSelfAddr(b->links[0], buf, sizeof(buf)) == 0) { |
| |
DST_COPY(buf); |
| |
} else { |
| |
DST_COPY("-"); |
| |
} |
| |
break; |
| |
/* peer "physycal" address */ |
| |
case 'O': |
| |
if (b->links[0] && PhysGetPeerAddr(b->links[0], buf, sizeof(buf)) == 0) { |
| |
DST_COPY(buf); |
| |
} else { |
| |
DST_COPY("-"); |
| |
} |
| |
break; |
| |
/* peer port */ |
| |
case 'P': |
| |
if (b->links[0] && PhysGetPeerPort(b->links[0], buf, sizeof(buf)) == 0) { |
| |
DST_COPY(buf); |
| } else { |
} else { |
| DST_COPY("-"); |
DST_COPY("-"); |
| } |
} |