version 1.1.1.4, 2019/10/22 13:49:55
|
version 1.1.1.5, 2021/03/17 00:39:23
|
Line 15
|
Line 15
|
|
|
#include <paths.h> |
#include <paths.h> |
#include <net/ethernet.h> |
#include <net/ethernet.h> |
|
#include <net/if.h> |
#include <netgraph/ng_message.h> |
#include <netgraph/ng_message.h> |
#include <netgraph/ng_pppoe.h> |
#include <netgraph/ng_pppoe.h> |
#include <netgraph/ng_ether.h> |
#include <netgraph/ng_ether.h> |
Line 157 static u_short PppoeGetMru(Link l, int conf);
|
Line 158 static u_short PppoeGetMru(Link l, int conf);
|
static void PppoeCtrlReadEvent(int type, void *arg); |
static void PppoeCtrlReadEvent(int type, void *arg); |
static void PppoeConnectTimeout(void *arg); |
static void PppoeConnectTimeout(void *arg); |
static void PppoeStat(Context ctx); |
static void PppoeStat(Context ctx); |
static int PppoeSetCommand(Context ctx, int ac, char *av[], void *arg); | static int PppoeSetCommand(Context ctx, int ac, const char *const av[], const void *arg); |
static int PppoeOriginated(Link l); |
static int PppoeOriginated(Link l); |
static int PppoeIsSync(Link l); |
static int PppoeIsSync(Link l); |
static void PppoeGetNode(Link l); |
static void PppoeGetNode(Link l); |
Line 213 const struct cmdtab PppoeSetCmds[] = {
|
Line 214 const struct cmdtab PppoeSetCmds[] = {
|
#endif |
#endif |
{ "mac-format {format}", "Set RADIUS attribute 31 MAC format", |
{ "mac-format {format}", "Set RADIUS attribute 31 MAC format", |
PppoeSetCommand, NULL, 2, (void *)SET_MAC_FORMAT }, |
PppoeSetCommand, NULL, 2, (void *)SET_MAC_FORMAT }, |
{ NULL } | { NULL, NULL, NULL, NULL, 0, NULL } |
}; |
}; |
|
|
/* |
/* |
Line 237 struct PppoeIf {
|
Line 238 struct PppoeIf {
|
SLIST_HEAD(, PppoeList) list; |
SLIST_HEAD(, PppoeList) list; |
}; |
}; |
|
|
int PppoeIfCount=0; | static struct PppoeIf PppoeIfs[PPPOE_MAXPARENTIFS]; |
struct PppoeIf PppoeIfs[PPPOE_MAXPARENTIFS]; | |
|
|
struct tagname { |
struct tagname { |
int tag; |
int tag; |
Line 552 PppoeCtrlReadEvent(int type, void *arg)
|
Line 552 PppoeCtrlReadEvent(int type, void *arg)
|
PppoeInfo pi = NULL; |
PppoeInfo pi = NULL; |
|
|
struct PppoeIf *PIf = (struct PppoeIf*)arg; |
struct PppoeIf *PIf = (struct PppoeIf*)arg; |
| |
| (void)type; |
/* Read control message. */ |
/* Read control message. */ |
if (NgRecvMsg(PIf->csock, &u.resp, sizeof(u), path) < 0) { |
if (NgRecvMsg(PIf->csock, &u.resp, sizeof(u), path) < 0) { |
Perror("PPPoE: error reading message from \"%s\"", path); |
Perror("PPPoE: error reading message from \"%s\"", path); |
Line 645 PppoeCtrlReadEvent(int type, void *arg)
|
Line 646 PppoeCtrlReadEvent(int type, void *arg)
|
{ |
{ |
struct ngpppoe_maxp *maxp; |
struct ngpppoe_maxp *maxp; |
|
|
maxp = ((struct ngpppoe_maxp *)u.resp.data); | maxp = ((struct ngpppoe_maxp *)(void *)u.resp.data); |
Log(LG_PHYS, ("[%s] PPPoE: rec'd PPP-Max-Payload '%u'", |
Log(LG_PHYS, ("[%s] PPPoE: rec'd PPP-Max-Payload '%u'", |
l->name, maxp->data)); |
l->name, maxp->data)); |
if (pi->max_payload > 0) { |
if (pi->max_payload > 0) { |
Line 745 PppoeOriginated(Link l)
|
Line 746 PppoeOriginated(Link l)
|
static int |
static int |
PppoeIsSync(Link l) |
PppoeIsSync(Link l) |
{ |
{ |
|
(void)l; |
return (1); |
return (1); |
} |
} |
|
|
Line 753 PppoePeerMacAddr(Link l, void *buf, size_t buf_len)
|
Line 755 PppoePeerMacAddr(Link l, void *buf, size_t buf_len)
|
{ |
{ |
PppoeInfo const pppoe = (PppoeInfo)l->info; |
PppoeInfo const pppoe = (PppoeInfo)l->info; |
|
|
|
if (buf_len < 18) |
|
return (1); |
ether_ntoa_r((struct ether_addr *)pppoe->peeraddr, buf); |
ether_ntoa_r((struct ether_addr *)pppoe->peeraddr, buf); |
return (0); |
return (0); |
} |
} |
Line 901 CreatePppoeNode(struct PppoeIf *PIf, const char *iface
|
Line 905 CreatePppoeNode(struct PppoeIf *PIf, const char *iface
|
uint32_t f; |
uint32_t f; |
|
|
/* Make sure interface is up. */ |
/* Make sure interface is up. */ |
if (ExecCmdNosh(LG_PHYS2, iface, "%s %s up", _PATH_IFCONFIG, iface) != 0) { | if (IfaceSetFlag(iface, IFF_UP) != 0) { |
Log(LG_ERR, ("PPPoE: can't bring up interface %s", | Perror("[%s] PPPoE: can't bring up interface", iface); |
iface)); | |
return (0); |
return (0); |
} |
} |
|
|
/* Create a new netgraph node */ |
/* Create a new netgraph node */ |
if (NgMkSockNode(NULL, &PIf->csock, &PIf->dsock) < 0) { |
if (NgMkSockNode(NULL, &PIf->csock, &PIf->dsock) < 0) { |
Perror("[%s] PPPoE: can't create ctrl socket", iface); |
Perror("[%s] PPPoE: can't create ctrl socket", iface); |
return(0); | return (0); |
} |
} |
(void)fcntl(PIf->csock, F_SETFD, 1); |
(void)fcntl(PIf->csock, F_SETFD, 1); |
(void)fcntl(PIf->dsock, F_SETFD, 1); |
(void)fcntl(PIf->dsock, F_SETFD, 1); |
Line 940 CreatePppoeNode(struct PppoeIf *PIf, const char *iface
|
Line 942 CreatePppoeNode(struct PppoeIf *PIf, const char *iface
|
} |
} |
|
|
/* Look for NG_ETHER_NODE_TYPE. */ |
/* Look for NG_ETHER_NODE_TYPE. */ |
tlist = (const struct typelist*) resp->data; | tlist = (const struct typelist*)(void *)resp->data; |
for (f = 0; f < tlist->numtypes; f++) |
for (f = 0; f < tlist->numtypes; f++) |
if (strncmp(tlist->typeinfo[f].type_name, |
if (strncmp(tlist->typeinfo[f].type_name, |
NG_ETHER_NODE_TYPE, |
NG_ETHER_NODE_TYPE, |
Line 979 CreatePppoeNode(struct PppoeIf *PIf, const char *iface
|
Line 981 CreatePppoeNode(struct PppoeIf *PIf, const char *iface
|
return (0); |
return (0); |
} |
} |
|
|
hlist = (const struct hooklist *)resp->data; | hlist = (const struct hooklist *)(void *)resp->data; |
ninfo = &hlist->nodeinfo; |
ninfo = &hlist->nodeinfo; |
|
|
/* Make sure we've got the right type of node. */ |
/* Make sure we've got the right type of node. */ |
Line 1040 CreatePppoeNode(struct PppoeIf *PIf, const char *iface
|
Line 1042 CreatePppoeNode(struct PppoeIf *PIf, const char *iface
|
snprintf(path2, sizeof(path2), "%s%s", path, hook); |
snprintf(path2, sizeof(path2), "%s%s", path, hook); |
/* Get pppoe node ID */ |
/* Get pppoe node ID */ |
if ((PIf->node_id = NgGetNodeID(PIf->csock, path2)) == 0) { |
if ((PIf->node_id = NgGetNodeID(PIf->csock, path2)) == 0) { |
Perror("[%s] Cannot get pppoe node id", iface); | Perror("[%s] Cannot get %s node id", iface, |
| NG_PPPOE_NODE_TYPE); |
close(PIf->csock); |
close(PIf->csock); |
close(PIf->dsock); |
close(PIf->dsock); |
return (0); |
return (0); |
Line 1108 get_vs_tag(const struct pppoe_hdr* ph, uint32_t idx)
|
Line 1111 get_vs_tag(const struct pppoe_hdr* ph, uint32_t idx)
|
return (NULL); |
return (NULL); |
if (pt->tag_type == PTT_VENDOR && |
if (pt->tag_type == PTT_VENDOR && |
ntohs(pt->tag_len) >= 4 && |
ntohs(pt->tag_len) >= 4 && |
*(const uint32_t*)(pt + 1) == idx) | *(const uint32_t*)(const void *)(pt + 1) == idx) |
return (pt); |
return (pt); |
|
|
pt = (const struct pppoe_tag*)ptn; |
pt = (const struct pppoe_tag*)ptn; |
Line 1167 print_tags(const struct pppoe_hdr* ph)
|
Line 1170 print_tags(const struct pppoe_hdr* ph)
|
break; |
break; |
case PTT_VENDOR: |
case PTT_VENDOR: |
if (len >= 4) { |
if (len >= 4) { |
if ((uint8_t)*(uint8_t*)v != 0) { | if ((const uint8_t)*(const uint8_t*)v != 0) { |
snprintf(buf, sizeof(buf), |
snprintf(buf, sizeof(buf), |
"First byte of VENDOR is not zero! 0x%s", |
"First byte of VENDOR is not zero! 0x%s", |
Bin2Hex(v, len)); |
Bin2Hex(v, len)); |
Line 1184 print_tags(const struct pppoe_hdr* ph)
|
Line 1187 print_tags(const struct pppoe_hdr* ph)
|
if (len != 2) { |
if (len != 2) { |
sprintf(buf, "TAG_LENGTH is not 2!"); |
sprintf(buf, "TAG_LENGTH is not 2!"); |
} else { |
} else { |
sprintf(buf, "%u", *(uint16_t*)(pt + 1)); | sprintf(buf, "%u", *(const uint16_t*)(const void *)(pt + 1)); |
} |
} |
break; |
break; |
case PTT_SRV_ERR: |
case PTT_SRV_ERR: |
Line 1255 PppoeListenEvent(int type, void *arg)
|
Line 1258 PppoeListenEvent(int type, void *arg)
|
} u; |
} u; |
struct ngpppoe_init_data *const idata = &u.poeid; |
struct ngpppoe_init_data *const idata = &u.poeid; |
|
|
|
(void)type; |
switch (sz = NgRecvData(PIf->dsock, response, sizeof(response), rhook)) { |
switch (sz = NgRecvData(PIf->dsock, response, sizeof(response), rhook)) { |
case -1: |
case -1: |
Log(LG_ERR, ("NgRecvData: %d", sz)); |
Log(LG_ERR, ("NgRecvData: %d", sz)); |
Line 1271 PppoeListenEvent(int type, void *arg)
|
Line 1275 PppoeListenEvent(int type, void *arg)
|
|
|
session = rhook + 7; |
session = rhook + 7; |
|
|
if (sz < sizeof(struct pppoe_full_hdr)) { | if ((size_t)sz < sizeof(struct pppoe_full_hdr)) { |
Log(LG_PHYS, ("Incoming truncated PPPoE connection request via %s for " |
Log(LG_PHYS, ("Incoming truncated PPPoE connection request via %s for " |
"service \"%s\"", PIf->ifnodepath, session)); |
"service \"%s\"", PIf->ifnodepath, session)); |
return; |
return; |
Line 1280 PppoeListenEvent(int type, void *arg)
|
Line 1284 PppoeListenEvent(int type, void *arg)
|
wh = (struct pppoe_full_hdr *)response; |
wh = (struct pppoe_full_hdr *)response; |
ph = &wh->ph; |
ph = &wh->ph; |
if ((tag = get_tag(ph, PTT_SRV_NAME))) { |
if ((tag = get_tag(ph, PTT_SRV_NAME))) { |
int len = ntohs(tag->tag_len); | size_t len = ntohs(tag->tag_len); |
if (len >= sizeof(real_session)) |
if (len >= sizeof(real_session)) |
len = sizeof(real_session)-1; |
len = sizeof(real_session)-1; |
memcpy(real_session, tag + 1, len); |
memcpy(real_session, tag + 1, len); |
Line 1291 PppoeListenEvent(int type, void *arg)
|
Line 1295 PppoeListenEvent(int type, void *arg)
|
bzero(agent_cid, sizeof(agent_cid)); |
bzero(agent_cid, sizeof(agent_cid)); |
bzero(agent_rid, sizeof(agent_rid)); |
bzero(agent_rid, sizeof(agent_rid)); |
if ((tag = get_vs_tag(ph, htonl(0x00000DE9)))) { |
if ((tag = get_vs_tag(ph, htonl(0x00000DE9)))) { |
int len = ntohs(tag->tag_len) - 4, pos = 0; | size_t len = ntohs(tag->tag_len) - 4, pos = 0; |
const char *b = (const char *)(tag + 1) + 4; |
const char *b = (const char *)(tag + 1) + 4; |
while (pos + 1 <= len) { |
while (pos + 1 <= len) { |
int len1 = b[pos + 1]; | size_t len1 = b[pos + 1]; |
if (len1 > len - pos - 2) |
if (len1 > len - pos - 2) |
break; |
break; |
if (len1 >= sizeof(agent_rid)) |
if (len1 >= sizeof(agent_rid)) |
Line 1313 PppoeListenEvent(int type, void *arg)
|
Line 1317 PppoeListenEvent(int type, void *arg)
|
|
|
Log(LG_PHYS, ("Incoming PPPoE connection request via %s for " |
Log(LG_PHYS, ("Incoming PPPoE connection request via %s for " |
"service \"%s\" from %s", PIf->ifnodepath, real_session, |
"service \"%s\" from %s", PIf->ifnodepath, real_session, |
ether_ntoa((struct ether_addr *)&wh->eh.ether_shost))); | ether_ntoa((const struct ether_addr *)&wh->eh.ether_shost))); |
|
|
if (gLogOptions & LG_PHYS3) |
if (gLogOptions & LG_PHYS3) |
print_tags(ph); |
print_tags(ph); |
Line 1673 PppoeNodeUpdate(Link l)
|
Line 1677 PppoeNodeUpdate(Link l)
|
*/ |
*/ |
|
|
static int |
static int |
PppoeSetCommand(Context ctx, int ac, char *av[], void *arg) | PppoeSetCommand(Context ctx, int ac, const char *const av[], const void *arg) |
{ |
{ |
const PppoeInfo pi = (PppoeInfo) ctx->lnk->info; |
const PppoeInfo pi = (PppoeInfo) ctx->lnk->info; |
const char *hookname = ETHER_DEFAULT_HOOK; |
const char *hookname = ETHER_DEFAULT_HOOK; |