-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathvxlanctl.c
105 lines (82 loc) · 2.19 KB
/
vxlanctl.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* vxlanctl.c */
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <linux/un.h>
#include "common.h"
int create_unix_client_socket (char * domain);
void
usage (void)
{
printf ("\n"
" Usage :\n"
"\t vxlanctl [commands]\n"
"\n"
" commands: (VNI is hex)\n"
"\n"
" create <VNI> add vxlan interface\n"
" destroy <VNI> delete vxlan interface\n"
" acl <VNI> mac [deny|permit] <Mac Addr> Source Mac Address Filter\n"
" acl <VNI> arp [deny|permit] <v4Addr> ARP Target Address Filter\n"
" acl <VNI> ns [deny|permit] <v6Addr> NS Target Address Filter\n"
" acl <VNI> ra [deny|permit] RA Filter\n"
" acl <VNI> rs [deny|permit] RS FIlter\n"
"\n"
"\n"
" !! All Access List is Outbound Filter !!\n"
"\n"
);
return;
}
int
main (int argc, char * argv[])
{
int n, sock;
char cmdstr[512], resstr[512], buf[512];
if (argc < 2) {
usage ();
return 0;
}
if (strcmp (argv[1], "-h") == 0 ||
strcmp (argv[1], "--help") == 0) {
usage ();
return 0;
}
memset (cmdstr, 0, sizeof (cmdstr));
memset (resstr, 0, sizeof (resstr));
for (n = 1; n < argc; n++) {
strncpy (buf, cmdstr, sizeof (buf));
snprintf (cmdstr, sizeof (cmdstr), "%s %s", buf, argv[n]);
}
sock = create_unix_client_socket (VXLAN_UNIX_DOMAIN);
if (write (sock, cmdstr, strlen (cmdstr)) < 0) {
perror ("write");
shutdown (sock, SHUT_RDWR);
close (sock);
}
if (read (sock, resstr, sizeof (resstr)) < 0) {
perror ("read");
shutdown (sock, SHUT_RDWR);
close (sock);
}
printf ("%s", resstr);
return 0;
}
int
create_unix_client_socket (char * domain)
{
int sock;
struct sockaddr_un saddru;
memset (&saddru, 0, sizeof (saddru));
saddru.sun_family = AF_UNIX;
strncpy (saddru.sun_path, domain, UNIX_PATH_MAX);
if ((sock = socket (AF_UNIX, SOCK_STREAM, 0)) < 0)
err (EXIT_FAILURE, "can not create unix socket");
if (connect (sock, (struct sockaddr *)&saddru, sizeof (saddru)) != 0)
err (EXIT_FAILURE, "can not connect to unix socket \"%s\"", domain);
return sock;
}