summaryrefslogtreecommitdiff
path: root/ipoe-util/ipses-create.c
diff options
context:
space:
mode:
authorKozlov Dmitry <xeb@mail.ru>2012-06-26 19:17:34 +0400
committerKozlov Dmitry <xeb@mail.ru>2012-06-26 19:17:34 +0400
commit07264d491f0605088c94e8be9f2b593dd4882067 (patch)
tree58329f975626fc64ce220403721c03463121a12e /ipoe-util/ipses-create.c
parent2b256df842764409f0d1cd7a37afabcef4e2785b (diff)
downloadaccel-ppp-xebd-07264d491f0605088c94e8be9f2b593dd4882067.tar.gz
accel-ppp-xebd-07264d491f0605088c94e8be9f2b593dd4882067.zip
ipoe: initial implementation of kernel module
Diffstat (limited to 'ipoe-util/ipses-create.c')
-rw-r--r--ipoe-util/ipses-create.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/ipoe-util/ipses-create.c b/ipoe-util/ipses-create.c
new file mode 100644
index 0000000..5aaf1ab
--- /dev/null
+++ b/ipoe-util/ipses-create.c
@@ -0,0 +1,61 @@
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <string.h>
+#include <errno.h>
+#include <stdio.h>
+
+#include <netlink/netlink.h>
+#include <netlink/genl/genl.h>
+#include <netlink/genl/ctrl.h>
+
+
+#include "ipoe.h"
+
+int main(int argc, char **argv)
+{
+#if LIBNL2
+ struct nl_sock *h;
+#else
+ struct nl_handle *h;
+#endif
+ struct nl_msg *msg;
+ int family;
+ in_addr_t local, remote;
+ int err;
+
+ if (argc != 4) {
+ printf("usage: ipses-create <ifname> <peer_addr> <addr>\n");
+ return 1;
+ }
+
+ local = inet_addr(argv[2]);
+ remote = inet_addr(argv[3]);
+
+#if LIBNL2
+ h = nl_socket_alloc();
+#else
+ h = nl_handle_alloc();
+#endif
+ genl_connect(h);
+ family = genl_ctrl_resolve(h, IPOE_GENL_NAME);
+
+ msg = nlmsg_alloc();
+ genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, family, 0, NLM_F_REQUEST, IPOE_CMD_CREATE, IPOE_GENL_VERSION);
+ nla_put_u32(msg, IPOE_ATTR_PEER_ADDR, local);
+ nla_put_u32(msg, IPOE_ATTR_ADDR, remote);
+ nla_put_string(msg, IPOE_ATTR_IFNAME, argv[1]);
+
+ nl_send_auto_complete(h, msg);
+ err = nl_recvmsgs_default(h);
+#if LIBNL2
+ printf("recv: %s\n", nl_geterror(err));
+#else
+ nl_perror("recv");
+#endif
+
+ nlmsg_free(msg);
+ nl_close(h);
+
+ return 0;
+}
+