version 1.1, 2012/02/21 23:32:47
|
version 1.1.1.3, 2021/03/17 00:39:23
|
Line 26
|
Line 26
|
#define TCP_MRU 2048 |
#define TCP_MRU 2048 |
#define LISTENHOOK "listen" |
#define LISTENHOOK "listen" |
|
|
|
#ifndef SMALL_SYSTEM |
#define TCP_MAXPARENTIFS 256 |
#define TCP_MAXPARENTIFS 256 |
|
#else |
|
#define TCP_MAXPARENTIFS 64 |
|
#endif |
|
|
|
|
struct tcpinfo { |
struct tcpinfo { |
/* Configuration */ |
/* Configuration */ |
struct { |
struct { |
Line 87 static void TcpDoClose(Link l);
|
Line 92 static void TcpDoClose(Link l);
|
static void TcpAcceptEvent(int type, void *cookie); |
static void TcpAcceptEvent(int type, void *cookie); |
static void TcpConnectEvent(int type, void *cookie); |
static void TcpConnectEvent(int type, void *cookie); |
|
|
static int TcpSetCommand(Context ctx, int ac, char *av[], void *arg); | static int TcpSetCommand(Context ctx, int ac, const char *const av[], const void *arg); |
static void TcpNodeUpdate(Link l); |
static void TcpNodeUpdate(Link l); |
static int TcpListen(Link l); |
static int TcpListen(Link l); |
static void TcpUnListen(Link l); |
static void TcpUnListen(Link l); |
Line 127 const struct cmdtab TcpSetCmds[] = {
|
Line 132 const struct cmdtab TcpSetCmds[] = {
|
TcpSetCommand, NULL, 2, (void *) SET_ENABLE }, |
TcpSetCommand, NULL, 2, (void *) SET_ENABLE }, |
{ "disable [opt ...]", "Disable option", |
{ "disable [opt ...]", "Disable option", |
TcpSetCommand, NULL, 2, (void *) SET_DISABLE }, |
TcpSetCommand, NULL, 2, (void *) SET_DISABLE }, |
{ NULL }, | { NULL, NULL, NULL, NULL, 0, NULL }, |
}; |
}; |
|
|
struct TcpIf { |
struct TcpIf { |
Line 137 struct TcpIf {
|
Line 142 struct TcpIf {
|
int csock; /* netgraph Control socket */ |
int csock; /* netgraph Control socket */ |
EventRef ctrlEvent; /* listen for ctrl messages */ |
EventRef ctrlEvent; /* listen for ctrl messages */ |
}; |
}; |
struct TcpIf TcpIfs[TCP_MAXPARENTIFS]; | static struct TcpIf TcpIfs[TCP_MAXPARENTIFS]; |
|
|
/* |
/* |
* INTERNAL VARIABLES |
* INTERNAL VARIABLES |
*/ |
*/ |
|
|
static struct confinfo gConfList[] = { | static const struct confinfo gConfList[] = { |
{ 0, TCP_CONF_RESOLVE_ONCE, "resolve-once" }, |
{ 0, TCP_CONF_RESOLVE_ONCE, "resolve-once" }, |
{ 0, 0, NULL }, |
{ 0, 0, NULL }, |
}; |
}; |
Line 357 fail:
|
Line 362 fail:
|
static void |
static void |
TcpConnectEvent(int type, void *cookie) |
TcpConnectEvent(int type, void *cookie) |
{ |
{ |
struct { | union { |
| u_char buf[sizeof(struct ng_mesg) + sizeof(uint32_t)]; |
struct ng_mesg resp; |
struct ng_mesg resp; |
int32_t rval; |
|
} cn; |
} cn; |
|
uint32_t *const rval = (uint32_t *)(void *)cn.resp.data; |
|
|
Link l; |
Link l; |
TcpInfo pi; |
TcpInfo pi; |
char path[NG_PATHSIZ]; |
char path[NG_PATHSIZ]; |
Line 380 TcpConnectEvent(int type, void *cookie)
|
Line 387 TcpConnectEvent(int type, void *cookie)
|
assert(cn.resp.header.typecookie == NGM_KSOCKET_COOKIE); |
assert(cn.resp.header.typecookie == NGM_KSOCKET_COOKIE); |
assert(cn.resp.header.cmd == NGM_KSOCKET_CONNECT); |
assert(cn.resp.header.cmd == NGM_KSOCKET_CONNECT); |
|
|
if (cn.rval != 0) { | if (*rval != 0) { |
Log(LG_PHYS, ("[%s] failed to connect: %s", l->name, |
Log(LG_PHYS, ("[%s] failed to connect: %s", l->name, |
strerror(cn.rval))); | strerror(*rval))); |
goto failed; |
goto failed; |
} |
} |
|
|
Line 406 failed:
|
Line 413 failed:
|
static void |
static void |
TcpAcceptEvent(int type, void *cookie) |
TcpAcceptEvent(int type, void *cookie) |
{ |
{ |
struct { | union { |
struct ng_mesg resp; | |
uint32_t id; |
uint32_t id; |
struct sockaddr_storage sin; |
struct sockaddr_storage sin; |
|
u_char buf[sizeof(struct ng_mesg) + sizeof(uint32_t) |
|
+ sizeof(struct sockaddr_storage)]; |
|
struct ng_mesg resp; |
} ac; |
} ac; |
|
uint32_t *const id = (uint32_t *)(void *)ac.resp.data; |
|
struct sockaddr_storage *const sin = |
|
(struct sockaddr_storage*)(void *)(id + 1); |
|
|
struct ngm_name nm; |
struct ngm_name nm; |
char path[NG_PATHSIZ]; |
char path[NG_PATHSIZ]; |
struct u_addr addr; |
struct u_addr addr; |
Line 428 TcpAcceptEvent(int type, void *cookie)
|
Line 441 TcpAcceptEvent(int type, void *cookie)
|
Perror("TCP: error reading message from \"%s\"", path); |
Perror("TCP: error reading message from \"%s\"", path); |
goto failed; |
goto failed; |
} |
} |
sockaddrtou_addr(&ac.sin, &addr, &port); | sockaddrtou_addr(sin, &addr, &port); |
|
|
Log(LG_PHYS, ("Incoming TCP connection from %s %u", |
Log(LG_PHYS, ("Incoming TCP connection from %s %u", |
u_addrtoa(&addr, buf, sizeof(buf)), port)); |
u_addrtoa(&addr, buf, sizeof(buf)), port)); |
Line 477 TcpAcceptEvent(int type, void *cookie)
|
Line 490 TcpAcceptEvent(int type, void *cookie)
|
Log(LG_PHYS, ("[%s] Accepting TCP connection from %s %u", |
Log(LG_PHYS, ("[%s] Accepting TCP connection from %s %u", |
l->name, u_addrtoa(&addr, buf, sizeof(buf)), port)); |
l->name, u_addrtoa(&addr, buf, sizeof(buf)), port)); |
|
|
sockaddrtou_addr(&ac.sin, &pi->peer_addr, &pi->peer_port); | sockaddrtou_addr(sin, &pi->peer_addr, &pi->peer_port); |
|
|
pi->node_id = ac.id; | pi->node_id = *id; |
|
|
/* Give it a name */ |
/* Give it a name */ |
snprintf(nm.name, sizeof(nm.name), "mpd%d-%s", gPid, l->name); |
snprintf(nm.name, sizeof(nm.name), "mpd%d-%s", gPid, l->name); |
snprintf(path, sizeof(path), "[%x]:", ac.id); | snprintf(path, sizeof(path), "[%x]:", *id); |
if (NgSendMsg(If->csock, path, |
if (NgSendMsg(If->csock, path, |
NGM_GENERIC_COOKIE, NGM_NAME, &nm, sizeof(nm)) < 0) { |
NGM_GENERIC_COOKIE, NGM_NAME, &nm, sizeof(nm)) < 0) { |
Perror("[%s] can't name %s node", |
Perror("[%s] can't name %s node", |
Line 497 TcpAcceptEvent(int type, void *cookie)
|
Line 510 TcpAcceptEvent(int type, void *cookie)
|
} else { |
} else { |
Log(LG_PHYS, ("No free TCP link with requested parameters " |
Log(LG_PHYS, ("No free TCP link with requested parameters " |
"was found")); |
"was found")); |
snprintf(path, sizeof(path), "[%x]:", ac.id); | snprintf(path, sizeof(path), "[%x]:", *id); |
NgFuncShutdownNode(If->csock, "", path); |
NgFuncShutdownNode(If->csock, "", path); |
} |
} |
|
|
Line 540 TcpClose(Link l)
|
Line 553 TcpClose(Link l)
|
static void |
static void |
TcpShutdown(Link l) |
TcpShutdown(Link l) |
{ |
{ |
TcpInfo const pi = (TcpInfo) l->info; | TcpInfo const pi = (TcpInfo) l->info; |
|
|
if (pi->conf.fqdn_peer_addr) | if (pi->conf.fqdn_peer_addr) |
Freee(pi->conf.fqdn_peer_addr); | Freee(pi->conf.fqdn_peer_addr); |
|
|
TcpDoClose(l); |
TcpDoClose(l); |
TcpUnListen(l); |
TcpUnListen(l); |
Line 602 TcpOriginate(Link l)
|
Line 615 TcpOriginate(Link l)
|
static int |
static int |
TcpIsSync(Link l) |
TcpIsSync(Link l) |
{ |
{ |
|
(void)l; |
return (1); |
return (1); |
} |
} |
|
|
Line 774 TcpListen(Link l)
|
Line 788 TcpListen(Link l)
|
/* Setsockopt socket. */ |
/* Setsockopt socket. */ |
ksso->level=SOL_SOCKET; |
ksso->level=SOL_SOCKET; |
ksso->name=SO_REUSEPORT; |
ksso->name=SO_REUSEPORT; |
((int *)(ksso->value))[0]=1; | ((int *)(void *)(ksso->value))[0]=1; |
if (NgSendMsg(pi->If->csock, LISTENHOOK, NGM_KSOCKET_COOKIE, |
if (NgSendMsg(pi->If->csock, LISTENHOOK, NGM_KSOCKET_COOKIE, |
NGM_KSOCKET_SETOPT, &u, sizeof(u)) < 0) { |
NGM_KSOCKET_SETOPT, &u, sizeof(u)) < 0) { |
Perror("TCP: can't setsockopt() %s node", NG_KSOCKET_NODE_TYPE); |
Perror("TCP: can't setsockopt() %s node", NG_KSOCKET_NODE_TYPE); |
Line 858 TcpNodeUpdate(Link l)
|
Line 872 TcpNodeUpdate(Link l)
|
*/ |
*/ |
|
|
static int |
static int |
TcpSetCommand(Context ctx, int ac, char *av[], void *arg) | TcpSetCommand(Context ctx, int ac, const char *const av[], const void *arg) |
{ |
{ |
TcpInfo const pi = (TcpInfo) ctx->lnk->info; |
TcpInfo const pi = (TcpInfo) ctx->lnk->info; |
char **fqdn_peer_addr = &pi->conf.fqdn_peer_addr; |
char **fqdn_peer_addr = &pi->conf.fqdn_peer_addr; |