]>
Commit | Line | Data |
---|---|---|
908755dc JL |
1 | /* |
2 | * iplink_geneve.c GENEVE device support | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the GNU General Public License | |
6 | * as published by the Free Software Foundation; either version | |
7 | * 2 of the License, or (at your option) any later version. | |
8 | * | |
9 | * Authors: John W. Linville <linville@tuxdriver.com> | |
10 | */ | |
11 | ||
12 | #include <stdio.h> | |
13 | ||
14 | #include "utils.h" | |
15 | #include "ip_common.h" | |
16 | ||
17 | static void print_explain(FILE *f) | |
18 | { | |
19 | fprintf(f, "Usage: ... geneve id VNI remote ADDR\n"); | |
20 | fprintf(f, "\n"); | |
21 | fprintf(f, "Where: VNI := 0-16777215\n"); | |
22 | fprintf(f, " ADDR := IP_ADDRESS\n"); | |
23 | } | |
24 | ||
25 | static void explain(void) | |
26 | { | |
27 | print_explain(stderr); | |
28 | } | |
29 | ||
30 | static int geneve_parse_opt(struct link_util *lu, int argc, char **argv, | |
31 | struct nlmsghdr *n) | |
32 | { | |
33 | __u32 vni = 0; | |
34 | int vni_set = 0; | |
35 | __u32 daddr = 0; | |
36 | struct in6_addr daddr6 = IN6ADDR_ANY_INIT; | |
37 | ||
38 | ||
39 | while (argc > 0) { | |
40 | if (!matches(*argv, "id") || | |
41 | !matches(*argv, "vni")) { | |
42 | NEXT_ARG(); | |
43 | if (get_u32(&vni, *argv, 0) || | |
44 | vni >= 1u << 24) | |
45 | invarg("invalid id", *argv); | |
46 | vni_set = 1; | |
47 | } else if (!matches(*argv, "remote")) { | |
48 | NEXT_ARG(); | |
49 | if (!inet_get_addr(*argv, &daddr, &daddr6)) { | |
50 | fprintf(stderr, "Invalid address \"%s\"\n", *argv); | |
51 | return -1; | |
52 | } | |
53 | if (IN_MULTICAST(ntohl(daddr))) | |
54 | invarg("invalid remote address", *argv); | |
55 | } else if (matches(*argv, "help") == 0) { | |
56 | explain(); | |
57 | return -1; | |
58 | } else { | |
59 | fprintf(stderr, "geneve: unknown command \"%s\"?\n", *argv); | |
60 | explain(); | |
61 | return -1; | |
62 | } | |
63 | argc--, argv++; | |
64 | } | |
65 | ||
66 | if (!vni_set) { | |
67 | fprintf(stderr, "geneve: missing virtual network identifier\n"); | |
68 | return -1; | |
69 | } | |
70 | ||
71 | if (!daddr) { | |
72 | fprintf(stderr, "geneve: remove link partner not specified\n"); | |
73 | return -1; | |
74 | } | |
75 | if (memcmp(&daddr6, &in6addr_any, sizeof(daddr6)) != 0) { | |
76 | fprintf(stderr, "geneve: remove link over IPv6 not supported\n"); | |
77 | return -1; | |
78 | } | |
79 | ||
80 | addattr32(n, 1024, IFLA_GENEVE_ID, vni); | |
81 | if (daddr) | |
82 | addattr_l(n, 1024, IFLA_GENEVE_REMOTE, &daddr, 4); | |
83 | ||
84 | return 0; | |
85 | } | |
86 | ||
87 | static void geneve_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) | |
88 | { | |
89 | __u32 vni; | |
90 | char s1[1024]; | |
91 | ||
92 | if (!tb) | |
93 | return; | |
94 | ||
95 | if (!tb[IFLA_GENEVE_ID] || | |
96 | RTA_PAYLOAD(tb[IFLA_GENEVE_ID]) < sizeof(__u32)) | |
97 | return; | |
98 | ||
99 | vni = rta_getattr_u32(tb[IFLA_GENEVE_ID]); | |
100 | fprintf(f, "id %u ", vni); | |
101 | ||
102 | if (tb[IFLA_GENEVE_REMOTE]) { | |
103 | __be32 addr = rta_getattr_u32(tb[IFLA_GENEVE_REMOTE]); | |
104 | if (addr) | |
105 | fprintf(f, "remote %s ", | |
106 | format_host(AF_INET, 4, &addr, s1, sizeof(s1))); | |
107 | } | |
108 | } | |
109 | ||
110 | static void geneve_print_help(struct link_util *lu, int argc, char **argv, | |
111 | FILE *f) | |
112 | { | |
113 | print_explain(f); | |
114 | } | |
115 | ||
116 | struct link_util geneve_link_util = { | |
117 | .id = "geneve", | |
118 | .maxattr = IFLA_GENEVE_MAX, | |
119 | .parse_opt = geneve_parse_opt, | |
120 | .print_opt = geneve_print_opt, | |
121 | .print_help = geneve_print_help, | |
122 | }; |