summaryrefslogtreecommitdiff
path: root/accel-pppd/net.c
diff options
context:
space:
mode:
authorDmitry Kozlov <xeb@mail.ru>2016-04-15 16:06:20 +0300
committerDmitry Kozlov <xeb@mail.ru>2016-04-15 17:24:10 +0300
commitb80e64a320b22c0e966ec1e42bda4929d5a748ec (patch)
tree3c05fd9248574d0939d86652e8a0e3eb8f7dd269 /accel-pppd/net.c
parent7de0d2d00be552dede15dfd02c9e423dda7eb6f5 (diff)
downloadaccel-ppp-b80e64a320b22c0e966ec1e42bda4929d5a748ec.tar.gz
accel-ppp-b80e64a320b22c0e966ec1e42bda4929d5a748ec.zip
preparation for DPDK intergation (part 6)
Diffstat (limited to 'accel-pppd/net.c')
-rw-r--r--accel-pppd/net.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/accel-pppd/net.c b/accel-pppd/net.c
index ddf2d2f8..d2bd4e03 100644
--- a/accel-pppd/net.c
+++ b/accel-pppd/net.c
@@ -1,5 +1,6 @@
#include <unistd.h>
#include <fcntl.h>
+#include <string.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
@@ -7,6 +8,11 @@
#include "ap_net.h"
+#define MAX_NET 2
+
+static const struct ap_net *nets[MAX_NET];
+static int net_cnt;
+
extern int sock_fd;
__export __thread const struct ap_net *net;
@@ -77,6 +83,7 @@ static int def_sock_ioctl(unsigned long request, void *arg)
}
__export const struct ap_net def_net = {
+ .name = "kernel",
.socket = def_socket,
.connect = def_connect,
.bind = def_bind,
@@ -91,3 +98,38 @@ __export const struct ap_net def_net = {
.ppp_ioctl = def_ppp_ioctl,
.sock_ioctl = def_sock_ioctl,
};
+
+static void __init init()
+{
+ nets[0] = &def_net;
+ net_cnt = 1;
+}
+
+int __export ap_net_register(const struct ap_net *net)
+{
+ int i;
+
+ if (net_cnt == MAX_NET)
+ return -1;
+
+ for (i = 0; i < net_cnt; i++) {
+ if (!strcmp(net->name, nets[i]->name))
+ return -1;
+ }
+
+ nets[net_cnt++] = net;
+
+ return 0;
+}
+
+__export const struct ap_net *ap_net_find(const char *name)
+{
+ int i;
+
+ for (i = 0; i < net_cnt; i++) {
+ if (!strcmp(name, nets[i]->name))
+ return nets[i];
+ }
+
+ return NULL;
+}