summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Kozlov <xeb@mail.ru>2014-09-13 21:12:11 +0400
committerDmitry Kozlov <xeb@mail.ru>2014-09-13 21:17:59 +0400
commit806fbb0bb5e7b42cc03aea3f110df72aeb2fd84c (patch)
treed7b46feccf14baaaa0522015342128a755e3b76c
parent96b5cb33e6a79f36c716e07e42da5008ca898494 (diff)
downloadaccel-ppp-806fbb0bb5e7b42cc03aea3f110df72aeb2fd84c.tar.gz
accel-ppp-806fbb0bb5e7b42cc03aea3f110df72aeb2fd84c.zip
pppoe: start interfaces asynchronously
When there are many interfaces to start accel-ppp stucks on startup because kernel slowly creates raw sockets. So starting this proccess asynchronous improves accel-ppp responsiveness
-rw-r--r--accel-pppd/ctrl/pppoe/pppoe.c50
-rw-r--r--accel-pppd/triton/triton.c9
2 files changed, 35 insertions, 24 deletions
diff --git a/accel-pppd/ctrl/pppoe/pppoe.c b/accel-pppd/ctrl/pppoe/pppoe.c
index 7c0bd766..b1445c24 100644
--- a/accel-pppd/ctrl/pppoe/pppoe.c
+++ b/accel-pppd/ctrl/pppoe/pppoe.c
@@ -232,7 +232,7 @@ static struct pppoe_conn_t *allocate_channel(struct pppoe_serv_t *serv, const ui
conn = mempool_alloc(conn_pool);
if (!conn) {
- log_emerg("pppoe: out of memory\n");
+ log_error("pppoe: out of memory\n");
return NULL;
}
@@ -1344,7 +1344,7 @@ static void __pppoe_server_start(const char *ifname, const char *opt, void *cli)
if (sock < 0) {
if (cli)
cli_sendv(cli, "socket: %s\r\n", strerror(errno));
- log_emerg("pppoe: socket: %s\n", strerror(errno));
+ log_error("pppoe: socket: %s\n", strerror(errno));
_free(serv);
return;
}
@@ -1354,7 +1354,7 @@ static void __pppoe_server_start(const char *ifname, const char *opt, void *cli)
if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &f, sizeof(f))) {
if (cli)
cli_sendv(cli, "setsockopt(SO_BROADCAST): %s\r\n", strerror(errno));
- log_emerg("pppoe: setsockopt(SO_BROADCAST): %s\n", strerror(errno));
+ log_error("pppoe: setsockopt(SO_BROADCAST): %s\n", strerror(errno));
goto out_err;
}
@@ -1362,13 +1362,13 @@ static void __pppoe_server_start(const char *ifname, const char *opt, void *cli)
if (ioctl(sock, SIOCGIFHWADDR, &ifr)) {
if (cli)
cli_sendv(cli, "ioctl(SIOCGIFHWADDR): %s\r\n", strerror(errno));
- log_emerg("pppoe: ioctl(SIOCGIFHWADDR): %s\n", strerror(errno));
+ log_error("pppoe: ioctl(SIOCGIFHWADDR): %s\n", strerror(errno));
goto out_err;
}
#ifdef ARPHDR_ETHER
if (ifr.ifr_hwaddr.sa_family != ARPHDR_ETHER) {
- log_emerg("pppoe: interface %s is not ethernet\n", ifname);
+ log_error("pppoe: interface %s is not ethernet\n", ifname);
goto out_err;
}
#endif
@@ -1376,7 +1376,7 @@ static void __pppoe_server_start(const char *ifname, const char *opt, void *cli)
if ((ifr.ifr_hwaddr.sa_data[0] & 1) != 0) {
if (cli)
cli_sendv(cli, "interface %s has not unicast address\r\n", ifname);
- log_emerg("pppoe: interface %s has not unicast address\n", ifname);
+ log_error("pppoe: interface %s has not unicast address\n", ifname);
goto out_err;
}
@@ -1385,20 +1385,20 @@ static void __pppoe_server_start(const char *ifname, const char *opt, void *cli)
if (ioctl(sock, SIOCGIFMTU, &ifr)) {
if (cli)
cli_sendv(cli, "ioctl(SIOCGIFMTU): %s\r\n", strerror(errno));
- log_emerg("pppoe: ioctl(SIOCGIFMTU): %s\n", strerror(errno));
+ log_error("pppoe: ioctl(SIOCGIFMTU): %s\n", strerror(errno));
goto out_err;
}
if (ifr.ifr_mtu < ETH_DATA_LEN) {
if (cli)
cli_sendv(cli, "interface %s has MTU of %i, should be %i\r\n", ifname, ifr.ifr_mtu, ETH_DATA_LEN);
- log_emerg("pppoe: interface %s has MTU of %i, should be %i\n", ifname, ifr.ifr_mtu, ETH_DATA_LEN);
+ log_error("pppoe: interface %s has MTU of %i, should be %i\n", ifname, ifr.ifr_mtu, ETH_DATA_LEN);
}
if (ioctl(sock, SIOCGIFINDEX, &ifr)) {
if (cli)
cli_sendv(cli, "ioctl(SIOCGIFINDEX): %s\r\n", strerror(errno));
- log_emerg("pppoe: ioctl(SIOCGIFINDEX): %s\n", strerror(errno));
+ log_error("pppoe: ioctl(SIOCGIFINDEX): %s\n", strerror(errno));
goto out_err;
}
@@ -1410,14 +1410,14 @@ static void __pppoe_server_start(const char *ifname, const char *opt, void *cli)
if (bind(sock, (struct sockaddr *)&sa, sizeof(sa))) {
if (cli)
cli_sendv(cli, "bind: %s\n", strerror(errno));
- log_emerg("pppoe: bind: %s\n", strerror(errno));
+ log_error("pppoe: bind: %s\n", strerror(errno));
goto out_err;
}
if (fcntl(sock, F_SETFL, O_NONBLOCK)) {
if (cli)
cli_sendv(cli, "failed to set nonblocking mode: %s\n", strerror(errno));
- log_emerg("pppoe: failed to set nonblocking mode: %s\n", strerror(errno));
+ log_error("pppoe: failed to set nonblocking mode: %s\n", strerror(errno));
goto out_err;
}
@@ -1519,7 +1519,7 @@ static int init_secret(struct pppoe_serv_t *serv)
DES_cblock key;
if (read(urandom_fd, serv->secret, SECRET_LENGTH) < 0) {
- log_emerg("pppoe: failed to read /dev/urandom: %s\n", strerror(errno));
+ log_error("pppoe: failed to read /dev/urandom: %s\n", strerror(errno));
return -1;
}
@@ -1623,10 +1623,21 @@ static void load_config(void)
}
}
-static void pppoe_init(void)
+static void load_interfaces()
{
struct conf_sect_t *s = conf_get_section("pppoe");
struct conf_option_t *opt;
+
+ list_for_each_entry(opt, &s->items, entry) {
+ if (!strcmp(opt->name, "interface")) {
+ if (opt->val)
+ pppoe_server_start(opt->val, NULL);
+ }
+ }
+}
+
+static void pppoe_init(void)
+{
int fd;
uint8_t *ptr;
@@ -1646,23 +1657,18 @@ static void pppoe_init(void)
pado_pool = mempool_create(sizeof(struct delayed_pado_t));
padi_pool = mempool_create(sizeof(struct padi_t));
- if (!s) {
- log_emerg("pppoe: no configuration, disabled...\n");
+ if (!conf_get_section("pppoe")) {
+ log_error("pppoe: no configuration, disabled...\n");
return;
}
- list_for_each_entry(opt, &s->items, entry) {
- if (!strcmp(opt->name, "interface")) {
- if (opt->val)
- pppoe_server_start(opt->val, NULL);
- }
- }
-
load_config();
connlimit_loaded = triton_module_loaded("connlimit");
triton_event_register_handler(EV_CONFIG_RELOAD, (triton_event_func)load_config);
+
+ triton_context_call(NULL, (triton_event_func)load_interfaces, NULL);
}
DEFINE_INIT(21, pppoe_init);
diff --git a/accel-pppd/triton/triton.c b/accel-pppd/triton/triton.c
index cdcccdb8..3c4de31d 100644
--- a/accel-pppd/triton/triton.c
+++ b/accel-pppd/triton/triton.c
@@ -485,13 +485,18 @@ void __export triton_context_wakeup(struct triton_context_t *ud)
int __export triton_context_call(struct triton_context_t *ud, void (*func)(void *), void *arg)
{
- struct _triton_context_t *ctx = (struct _triton_context_t *)ud->tpd;
+ struct _triton_context_t *ctx;
struct _triton_ctx_call_t *call = mempool_alloc(call_pool);
int r;
if (!call)
return -1;
-
+
+ if (ud)
+ ctx = (struct _triton_context_t *)ud->tpd;
+ else
+ ctx = (struct _triton_context_t *)default_ctx.tpd;
+
call->func = func;
call->arg = arg;