diff options
author | Dmitry Kozlov <xeb@mail.ru> | 2015-11-22 00:39:20 +0300 |
---|---|---|
committer | Dmitry Kozlov <xeb@mail.ru> | 2015-12-04 21:01:53 +0300 |
commit | bf84f9763ca3b6f018774b2b1664e838e119b028 (patch) | |
tree | 41cfefc92766e120bacf8974e77a267af881995a | |
parent | 9ba935fac2880939921d98b0b238d11a8cf1f3f6 (diff) | |
download | accel-ppp-bf84f9763ca3b6f018774b2b1664e838e119b028.tar.gz accel-ppp-bf84f9763ca3b6f018774b2b1664e838e119b028.zip |
preparation for DPDK intergation
-rw-r--r-- | accel-pppd/CMakeLists.txt | 1 | ||||
-rw-r--r-- | accel-pppd/ctrl/ipoe/ipoe.c | 10 | ||||
-rw-r--r-- | accel-pppd/ctrl/l2tp/l2tp.c | 12 | ||||
-rw-r--r-- | accel-pppd/ctrl/pppoe/pppoe.c | 25 | ||||
-rw-r--r-- | accel-pppd/ctrl/pppoe/pppoe.h | 2 | ||||
-rw-r--r-- | accel-pppd/ctrl/pptp/pptp.c | 10 | ||||
-rw-r--r-- | accel-pppd/include/ap_session.h | 15 | ||||
-rw-r--r-- | accel-pppd/net.c | 42 |
8 files changed, 102 insertions, 15 deletions
diff --git a/accel-pppd/CMakeLists.txt b/accel-pppd/CMakeLists.txt index ab96bc0..314a9f8 100644 --- a/accel-pppd/CMakeLists.txt +++ b/accel-pppd/CMakeLists.txt @@ -55,6 +55,7 @@ ADD_EXECUTABLE(accel-pppd session.c session_backup.c ifcfg.c + net.c backup/backup.c diff --git a/accel-pppd/ctrl/ipoe/ipoe.c b/accel-pppd/ctrl/ipoe/ipoe.c index 536fb25..46f1cac 100644 --- a/accel-pppd/ctrl/ipoe/ipoe.c +++ b/accel-pppd/ctrl/ipoe/ipoe.c @@ -196,6 +196,12 @@ static void __ipoe_session_start(struct ipoe_session *ses); static int ipoe_rad_send_auth_request(struct rad_plugin_t *rad, struct rad_packet_t *pack); static int ipoe_rad_send_acct_request(struct rad_plugin_t *rad, struct rad_packet_t *pack); +static void ipoe_ctx_switch(struct triton_context_t *ctx, void *arg) +{ + net = &def_net; + ipoe_ctx_switch(ctx, arg); +} + static struct ipoe_session *ipoe_session_lookup(struct ipoe_serv *serv, struct dhcpv4_packet *pack, struct ipoe_session **opt82_ses) { struct ipoe_session *ses, *res = NULL; @@ -1873,7 +1879,7 @@ struct ipoe_session *ipoe_session_alloc(void) ses->ifindex = -1; - ses->ctx.before_switch = log_switch; + ses->ctx.before_switch = ipoe_ctx_switch; ses->ctx.close = ipoe_session_close; ses->ctrl.ctx = &ses->ctx; ses->ctrl.started = ipoe_session_started; @@ -2575,7 +2581,7 @@ static void add_interface(const char *ifname, int ifindex, const char *opt, int serv = _malloc(sizeof(*serv)); memset(serv, 0, sizeof(*serv)); serv->ctx.close = ipoe_serv_close; - serv->ctx.before_switch = log_switch; + serv->ctx.before_switch = ipoe_ctx_switch; pthread_mutex_init(&serv->lock, NULL); serv->ifname = _strdup(ifname); serv->ifindex = ifindex; diff --git a/accel-pppd/ctrl/l2tp/l2tp.c b/accel-pppd/ctrl/l2tp/l2tp.c index befe0c9..6350e8e 100644 --- a/accel-pppd/ctrl/l2tp/l2tp.c +++ b/accel-pppd/ctrl/l2tp/l2tp.c @@ -253,6 +253,12 @@ static inline int nsnr_cmp(uint16_t ns, uint16_t nr) return (sub_nsnr != 0 && sub_nsnr < ref) - (sub_nsnr >= ref); } +static void l2tp_ctx_switch(struct triton_context_t *ctx, void *arg) +{ + net = &def_net; + log_switch(ctx, arg); +} + static inline struct l2tp_conn_t *l2tp_tunnel_self(void) { return container_of(triton_context_self(), struct l2tp_conn_t, ctx); @@ -1684,7 +1690,7 @@ static struct l2tp_conn_t *l2tp_tunnel_alloc(const struct sockaddr_in *peer, conn->state = STATE_INIT; conn->framing_cap = framing_cap; - conn->ctx.before_switch = log_switch; + conn->ctx.before_switch = l2tp_ctx_switch; conn->ctx.close = l2tp_conn_close; conn->hnd.read = l2tp_conn_read; conn->timeout_timer.expire = l2tp_tunnel_timeout; @@ -1741,7 +1747,7 @@ static inline int l2tp_tunnel_update_peerport(struct l2tp_conn_t *conn, static int l2tp_session_start_data_channel(struct l2tp_sess_t *sess) { - sess->apses_ctx.before_switch = log_switch; + sess->apses_ctx.before_switch = l2tp_ctx_switch; sess->apses_ctx.close = apses_ctx_stop; sess->ctrl.ctx = &sess->apses_ctx; @@ -4436,7 +4442,7 @@ static struct l2tp_serv_t udp_serv = { .hnd.read = l2tp_udp_read, .ctx.close = l2tp_udp_close, - .ctx.before_switch = log_switch, + .ctx.before_switch = l2tp_ctx_switch, }; /*static struct l2tp_serv_t ip_serv = diff --git a/accel-pppd/ctrl/pppoe/pppoe.c b/accel-pppd/ctrl/pppoe/pppoe.c index fc8a032..a9cbfbe 100644 --- a/accel-pppd/ctrl/pppoe/pppoe.c +++ b/accel-pppd/ctrl/pppoe/pppoe.c @@ -252,6 +252,13 @@ static int pppoe_rad_send_accounting_request(struct rad_plugin_t *rad, struct ra } #endif +static void pppoe_conn_ctx_switch(struct triton_context_t *ctx, void *arg) +{ + struct pppoe_conn_t *conn = arg; + net = conn->serv->net; + log_switch(ctx, &conn->ppp.ses); +} + static struct pppoe_conn_t *allocate_channel(struct pppoe_serv_t *serv, const uint8_t *addr, const struct pppoe_tag *host_uniq, const struct pppoe_tag *relay_sid, const struct pppoe_tag *service_name, const struct pppoe_tag *tr101, const uint8_t *cookie) { struct pppoe_conn_t *conn; @@ -318,7 +325,7 @@ static struct pppoe_conn_t *allocate_channel(struct pppoe_serv_t *serv, const ui memcpy(conn->cookie, cookie, COOKIE_LENGTH - 4); - conn->ctx.before_switch = log_switch; + conn->ctx.before_switch = pppoe_conn_ctx_switch; conn->ctx.close = pppoe_conn_close; conn->ctrl.ctx = &conn->ctx; conn->ctrl.started = ppp_started; @@ -386,7 +393,7 @@ static struct pppoe_conn_t *allocate_channel(struct pppoe_serv_t *serv, const ui if (conf_ip_pool) conn->ppp.ses.ipv4_pool_name = _strdup(conf_ip_pool); - triton_context_register(&conn->ctx, &conn->ppp.ses); + triton_context_register(&conn->ctx, conn); pthread_mutex_lock(&serv->lock); list_add_tail(&conn->entry, &serv->conn_list); @@ -1301,6 +1308,13 @@ void pppoe_server_start(const char *opt, void *cli) __pppoe_server_start(opt, opt, cli, 0, 0); } +static void pppoe_serv_ctx_switch(struct triton_context_t *ctx, void *arg) +{ + struct pppoe_serv_t *serv = arg; + net = serv->net; + log_switch(ctx, NULL); +} + static void __pppoe_server_start(const char *ifname, const char *opt, void *cli, int parent_ifindex, int vid) { struct pppoe_serv_t *serv; @@ -1380,9 +1394,10 @@ static void __pppoe_server_start(const char *ifname, const char *opt, void *cli, } serv->ctx.close = pppoe_serv_close; - serv->ctx.before_switch = log_switch; + serv->ctx.before_switch = pppoe_serv_ctx_switch; serv->ifname = _strdup(ifname); serv->ifindex = ifr.ifr_ifindex; + serv->net = &def_net; pthread_mutex_init(&serv->lock, NULL); INIT_LIST_HEAD(&serv->conn_list); @@ -1390,7 +1405,7 @@ static void __pppoe_server_start(const char *ifname, const char *opt, void *cli, INIT_LIST_HEAD(&serv->padi_list); serv->padi_limit = padi_limit; - triton_context_register(&serv->ctx, NULL); + triton_context_register(&serv->ctx, serv); if (vid) { serv->parent_ifindex = parent_ifindex; @@ -1408,8 +1423,6 @@ static void __pppoe_server_start(const char *ifname, const char *opt, void *cli, triton_context_wakeup(&serv->ctx); - pppoe_disc_start(serv); - return; out_err: diff --git a/accel-pppd/ctrl/pppoe/pppoe.h b/accel-pppd/ctrl/pppoe/pppoe.h index d044e4c..c28d96e 100644 --- a/accel-pppd/ctrl/pppoe/pppoe.h +++ b/accel-pppd/ctrl/pppoe/pppoe.h @@ -69,6 +69,8 @@ struct pppoe_serv_t struct triton_context_t ctx; struct rb_node node; + struct ap_net *net; + uint8_t hwaddr[ETH_ALEN]; char *ifname; int ifindex; diff --git a/accel-pppd/ctrl/pptp/pptp.c b/accel-pppd/ctrl/pptp/pptp.c index 94cfd7f..4a3090e 100644 --- a/accel-pppd/ctrl/pptp/pptp.c +++ b/accel-pppd/ctrl/pptp/pptp.c @@ -73,6 +73,12 @@ static void pptp_timeout(struct triton_timer_t *); static void ppp_started(struct ap_session *); static void ppp_finished(struct ap_session *); +static void pptp_ctx_switch(struct triton_context_t *ctx, void *arg) +{ + net = &def_net; + pptp_ctx_switch(ctx, arg); +} + static void disconnect(struct pptp_conn_t *conn) { log_ppp_debug("pptp: disconnect\n"); @@ -663,7 +669,7 @@ static int pptp_connect(struct triton_md_handler_t *h) conn->hnd.read = pptp_read; conn->hnd.write = pptp_write; conn->ctx.close = pptp_close; - conn->ctx.before_switch = log_switch; + conn->ctx.before_switch = pptp_ctx_switch; conn->in_buf = _malloc(PPTP_CTRL_SIZE_MAX); conn->out_buf = _malloc(PPTP_CTRL_SIZE_MAX); conn->timeout_timer.expire = pptp_timeout; @@ -714,7 +720,7 @@ static struct pptp_serv_t serv= { .hnd.read = pptp_connect, .ctx.close = pptp_serv_close, - .ctx.before_switch = log_switch, + .ctx.before_switch = pptp_ctx_switch, }; static int show_stat_exec(const char *cmd, char * const *fields, int fields_cnt, void *client) diff --git a/accel-pppd/include/ap_session.h b/accel-pppd/include/ap_session.h index 8bfe4cd..aea2fa6 100644 --- a/accel-pppd/include/ap_session.h +++ b/accel-pppd/include/ap_session.h @@ -36,9 +36,17 @@ struct ap_session; struct backup_data; struct rtnl_link_stats; +struct sockaddr; + +struct ap_net { + int (*pppox_socket)(int proto); + int (*pppox_connect)(int sock, const struct sockaddr *, socklen_t len); + int (*ppp_open)(); + int (*ppp_ioctl)(int fd, unsigned long request, void *arg); + int (*sock_ioctl)(unsigned long request, void *arg); +}; -struct ap_ctrl -{ +struct ap_ctrl { struct triton_context_t *ctx; int type; const char *name; @@ -128,6 +136,9 @@ extern int sock6_fd; // internet socket for ioctls extern int urandom_fd; extern struct ap_session_stat ap_session_stat; +extern __thread const struct ap_net *net; +extern const struct ap_net def_net; + void ap_session_init(struct ap_session *ses); void ap_session_set_ifindex(struct ap_session *ses); int ap_session_starting(struct ap_session *ses); diff --git a/accel-pppd/net.c b/accel-pppd/net.c new file mode 100644 index 0000000..b1db536 --- /dev/null +++ b/accel-pppd/net.c @@ -0,0 +1,42 @@ +#include <fcntl.h> +#include <sys/socket.h> +#include <sys/ioctl.h> + +#include "triton.h" + +#include "ap_session.h" + +__export __thread const struct ap_net *net; + +static int def_pppox_socket(int proto) +{ + return socket(AF_PPPOX, SOCK_STREAM, proto); +} + +static int def_pppox_connect(int sock, const struct sockaddr *addr, socklen_t len) +{ + return connect(sock, addr, len); +} + +static int def_ppp_open() +{ + return open("/dev/ppp", O_RDWR); +} + +static int def_ppp_ioctl(int fd, unsigned long request, void *arg) +{ + return ioctl(fd, request, arg); +} + +static int def_sock_ioctl(unsigned long request, void *arg) +{ + return ioctl(sock_fd, request, arg); +} + +const struct ap_net def_net = { + .pppox_socket = def_pppox_socket, + .pppox_connect = def_pppox_connect, + .ppp_open = def_ppp_open, + .ppp_ioctl = def_ppp_ioctl, + .sock_ioctl = def_sock_ioctl, +}; |