libnl: /data/src/libnl/lib/route/link/sit.c Source File

libnl 3.12.0

sit.c
1/* SPDX-License-Identifier: LGPL-2.1-only */
2/*
3 * Copyright (c) 2014 Susant Sahani <susant@redhat.com>
4 */
5
6/**
7 * @ingroup link
8 * @defgroup sit SIT
9 * sit link module
10 *
11 * @details
12 * \b Link Type Name: "sit"
13 *
14 * @route_doc{link_sit, SIT Documentation}
15 *
16 * @{
17 */
18
19#include "nl-default.h"
20
21#include <linux/if_tunnel.h>
22
23#include <netlink/netlink.h>
24#include <netlink/attr.h>
25#include <netlink/utils.h>
26#include <netlink/object.h>
27#include <netlink/route/rtnl.h>
28#include <netlink/route/link/sit.h>
29
30#include "nl-route.h"
31#include "link-api.h"
32#include "nl-aux-route/nl-route.h"
33
34#define SIT_ATTR_LINK (1 << 0)
35#define SIT_ATTR_LOCAL (1 << 1)
36#define SIT_ATTR_REMOTE (1 << 2)
37#define SIT_ATTR_TTL (1 << 3)
38#define SIT_ATTR_TOS (1 << 4)
39#define SIT_ATTR_PMTUDISC (1 << 5)
40#define SIT_ATTR_FLAGS (1 << 6)
41#define SIT_ATTR_PROTO (1 << 7)
42#define SIT_ATTR_6RD_PREFIX (1 << 8)
43#define SIT_ATTR_6RD_RELAY_PREFIX (1 << 9)
44#define SIT_ATTR_6RD_PREFIXLEN (1 << 10)
45#define SIT_ATTR_6RD_RELAY_PREFIXLEN (1 << 11)
46#define SIT_ATTR_FWMARK (1 << 12)
47
48 struct sit_info
49{
50 uint8_t ttl;
51 uint8_t tos;
52 uint8_t pmtudisc;
53 uint8_t proto;
54 uint16_t flags;
55 uint32_t link;
56 uint32_t local;
57 uint32_t remote;
58 struct in6_addr ip6rd_prefix;
59 uint32_t ip6rd_relay_prefix;
60 uint16_t ip6rd_prefixlen;
61 uint16_t ip6rd_relay_prefixlen;
62 uint32_t fwmark;
63 uint32_t sit_mask;
64};
65
66static struct nla_policy sit_policy[IFLA_IPTUN_MAX + 1] = {
67 [IFLA_IPTUN_LINK] = { .type = NLA_U32 },
68 [IFLA_IPTUN_LOCAL] = { .type = NLA_U32 },
69 [IFLA_IPTUN_REMOTE] = { .type = NLA_U32 },
70 [IFLA_IPTUN_TTL] = { .type = NLA_U8 },
71 [IFLA_IPTUN_TOS] = { .type = NLA_U8 },
72 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
73 [IFLA_IPTUN_FLAGS] = { .type = NLA_U16 },
74 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
75 [IFLA_IPTUN_6RD_PREFIX] = { .minlen = sizeof(struct in6_addr) },
76 [IFLA_IPTUN_6RD_RELAY_PREFIX] = { .type = NLA_U32 },
77 [IFLA_IPTUN_6RD_PREFIXLEN] = { .type = NLA_U16 },
78 [IFLA_IPTUN_6RD_RELAY_PREFIXLEN] = { .type = NLA_U16 },
79 [IFLA_IPTUN_FWMARK] = { .type = NLA_U32 },
80};
81
82static int sit_alloc(struct rtnl_link *link)
83{
84 struct sit_info *sit;
85
86 if (link->l_info)
87 memset(link->l_info, 0, sizeof(*sit));
88 else {
89 sit = calloc(1, sizeof(*sit));
90 if (!sit)
91 return -NLE_NOMEM;
92
93 link->l_info = sit;
94 }
95
96 return 0;
97}
98
99static int sit_parse(struct rtnl_link *link, struct nlattr *data,
100 struct nlattr *xstats)
101{
102 struct nlattr *tb[IFLA_IPTUN_MAX + 1];
103 struct sit_info *sit;
104 int err;
105
106 NL_DBG(3, "Parsing SIT link info\n");
107
108 err = nla_parse_nested(tb, IFLA_IPTUN_MAX, data, sit_policy);
109 if (err < 0)
110 goto errout;
111
112 err = sit_alloc(link);
113 if (err < 0)
114 goto errout;
115
116 sit = link->l_info;
117
118 if (tb[IFLA_IPTUN_LINK]) {
119 sit->link = nla_get_u32(tb[IFLA_IPTUN_LINK]);
120 sit->sit_mask |= SIT_ATTR_LINK;
121 }
122
123 if (tb[IFLA_IPTUN_LOCAL]) {
124 sit->local = nla_get_u32(tb[IFLA_IPTUN_LOCAL]);
125 sit->sit_mask |= SIT_ATTR_LOCAL;
126 }
127
128 if (tb[IFLA_IPTUN_REMOTE]) {
129 sit->remote = nla_get_u32(tb[IFLA_IPTUN_REMOTE]);
130 sit->sit_mask |= SIT_ATTR_REMOTE;
131 }
132
133 if (tb[IFLA_IPTUN_TTL]) {
134 sit->ttl = nla_get_u8(tb[IFLA_IPTUN_TTL]);
135 sit->sit_mask |= SIT_ATTR_TTL;
136 }
137
138 if (tb[IFLA_IPTUN_TOS]) {
139 sit->tos = nla_get_u8(tb[IFLA_IPTUN_TOS]);
140 sit->sit_mask |= SIT_ATTR_TOS;
141 }
142
143 if (tb[IFLA_IPTUN_PMTUDISC]) {
144 sit->pmtudisc = nla_get_u8(tb[IFLA_IPTUN_PMTUDISC]);
145 sit->sit_mask |= SIT_ATTR_PMTUDISC;
146 }
147
148 if (tb[IFLA_IPTUN_FLAGS]) {
149 sit->flags = nla_get_u16(tb[IFLA_IPTUN_FLAGS]);
150 sit->sit_mask |= SIT_ATTR_FLAGS;
151 }
152
153 if (tb[IFLA_IPTUN_PROTO]) {
154 sit->proto = nla_get_u8(tb[IFLA_IPTUN_PROTO]);
155 sit->sit_mask |= SIT_ATTR_PROTO;
156 }
157
158 if (tb[IFLA_IPTUN_6RD_PREFIX]) {
159 nla_memcpy(&sit->ip6rd_prefix, tb[IFLA_IPTUN_6RD_PREFIX],
160 sizeof(struct in6_addr));
161 sit->sit_mask |= SIT_ATTR_6RD_PREFIX;
162 }
163
164 if (tb[IFLA_IPTUN_6RD_RELAY_PREFIX]) {
165 sit->ip6rd_relay_prefix = nla_get_u32(tb[IFLA_IPTUN_6RD_RELAY_PREFIX]);
166 sit->sit_mask |= SIT_ATTR_6RD_RELAY_PREFIX;
167 }
168
169 if (tb[IFLA_IPTUN_6RD_PREFIXLEN]) {
170 sit->ip6rd_prefixlen = nla_get_u16(tb[IFLA_IPTUN_6RD_PREFIXLEN]);
171 sit->sit_mask |= SIT_ATTR_6RD_PREFIXLEN;
172 }
173
174 if (tb[IFLA_IPTUN_6RD_RELAY_PREFIXLEN]) {
175 sit->ip6rd_relay_prefixlen = nla_get_u16(tb[IFLA_IPTUN_6RD_RELAY_PREFIXLEN]);
176 sit->sit_mask |= SIT_ATTR_6RD_RELAY_PREFIXLEN;
177 }
178
179 if (tb[IFLA_IPTUN_FWMARK]) {
180 sit->fwmark = nla_get_u32(tb[IFLA_IPTUN_FWMARK]);
181 sit->sit_mask |= SIT_ATTR_FWMARK;
182 }
183
184 err = 0;
185
186errout:
187 return err;
188}
189
190static int sit_put_attrs(struct nl_msg *msg, struct rtnl_link *link)
191{
192 struct sit_info *sit = link->l_info;
193 struct nlattr *data;
194
195 data = nla_nest_start(msg, IFLA_INFO_DATA);
196 if (!data)
197 return -NLE_MSGSIZE;
198
199 if (sit->sit_mask & SIT_ATTR_LINK)
200 NLA_PUT_U32(msg, IFLA_IPTUN_LINK, sit->link);
201
202 if (sit->sit_mask & SIT_ATTR_LOCAL)
203 NLA_PUT_U32(msg, IFLA_IPTUN_LOCAL, sit->local);
204
205 if (sit->sit_mask & SIT_ATTR_REMOTE)
206 NLA_PUT_U32(msg, IFLA_IPTUN_REMOTE, sit->remote);
207
208 if (sit->sit_mask & SIT_ATTR_TTL)
209 NLA_PUT_U8(msg, IFLA_IPTUN_TTL, sit->ttl);
210
211 if (sit->sit_mask & SIT_ATTR_TOS)
212 NLA_PUT_U8(msg, IFLA_IPTUN_TOS, sit->tos);
213
214 if (sit->sit_mask & SIT_ATTR_PMTUDISC)
215 NLA_PUT_U8(msg, IFLA_IPTUN_PMTUDISC, sit->pmtudisc);
216
217 if (sit->sit_mask & SIT_ATTR_FLAGS)
218 NLA_PUT_U16(msg, IFLA_IPTUN_FLAGS, sit->flags);
219
220 if (sit->sit_mask & SIT_ATTR_PROTO)
221 NLA_PUT_U8(msg, IFLA_IPTUN_PROTO, sit->proto);
222
223 if (sit->sit_mask & SIT_ATTR_6RD_PREFIX)
224 NLA_PUT(msg, IFLA_IPTUN_6RD_PREFIX, sizeof(struct in6_addr), &sit->ip6rd_prefix);
225
226 if (sit->sit_mask & SIT_ATTR_6RD_RELAY_PREFIX)
227 NLA_PUT_U32(msg, IFLA_IPTUN_6RD_RELAY_PREFIX, sit->ip6rd_relay_prefix);
228
229 if (sit->sit_mask & SIT_ATTR_6RD_PREFIXLEN)
230 NLA_PUT_U16(msg, IFLA_IPTUN_6RD_PREFIXLEN, sit->ip6rd_prefixlen);
231
232 if (sit->sit_mask & SIT_ATTR_6RD_RELAY_PREFIXLEN)
233 NLA_PUT_U16(msg, IFLA_IPTUN_6RD_RELAY_PREFIXLEN, sit->ip6rd_relay_prefixlen);
234
235 if (sit->sit_mask & SIT_ATTR_FWMARK)
236 NLA_PUT_U32(msg, IFLA_IPTUN_FWMARK, sit->fwmark);
237
238 nla_nest_end(msg, data);
239
240nla_put_failure:
241
242 return 0;
243}
244
245static void sit_free(struct rtnl_link *link)
246{
247 struct sit_info *sit = link->l_info;
248
249 free(sit);
250 link->l_info = NULL;
251}
252
253static void sit_dump_line(struct rtnl_link *link, struct nl_dump_params *p)
254{
255 nl_dump(p, "sit : %s", link->l_name);
256}
257
258static void sit_dump_details(struct rtnl_link *link, struct nl_dump_params *p)
259{
260 struct sit_info *sit = link->l_info;
261 char addr[INET_ADDRSTRLEN], addr6[INET6_ADDRSTRLEN];
262
263 if (sit->sit_mask & SIT_ATTR_LINK) {
264 _nl_auto_rtnl_link struct rtnl_link *parent = NULL;
265 char *name;
266
267 nl_dump(p, " link ");
268
269 name = NULL;
270 parent = link_lookup(link->ce_cache, sit->link);
271 if (parent)
272 name = rtnl_link_get_name(parent);
273
274 if (name)
275 nl_dump_line(p, "%s\n", name);
276 else
277 nl_dump_line(p, "%u\n", sit->link);
278 }
279
280 if (sit->sit_mask & SIT_ATTR_LOCAL) {
281 nl_dump(p, " local ");
282 _nl_inet_ntop4(sit->local, addr);
283 nl_dump_line(p, "%s\n", addr);
284 }
285
286 if (sit->sit_mask & SIT_ATTR_REMOTE) {
287 nl_dump(p, " remote ");
288 _nl_inet_ntop4(sit->remote, addr);
289 nl_dump_line(p, "%s\n", addr);
290 }
291
292 if (sit->sit_mask & SIT_ATTR_TTL) {
293 nl_dump(p, " ttl ");
294 nl_dump_line(p, "%u\n", sit->ttl);
295 }
296
297 if (sit->sit_mask & SIT_ATTR_TOS) {
298 nl_dump(p, " tos ");
299 nl_dump_line(p, "%u\n", sit->tos);
300 }
301
302 if (sit->sit_mask & SIT_ATTR_FLAGS) {
303 nl_dump(p, " flags ");
304 nl_dump_line(p, " (%x)\n", sit->flags);
305 }
306
307 if (sit->sit_mask & SIT_ATTR_PROTO) {
308 nl_dump(p, " proto ");
309 nl_dump_line(p, " (%x)\n", sit->proto);
310 }
311
312 if (sit->sit_mask & SIT_ATTR_6RD_PREFIX) {
313 nl_dump(p, " 6rd_prefix ");
314 _nl_inet_ntop6(&sit->ip6rd_prefix, addr6);
315 nl_dump_line(p, "%s\n", addr6);
316 }
317
318 if (sit->sit_mask & SIT_ATTR_6RD_RELAY_PREFIX) {
319 nl_dump(p, " 6rd_relay_prefix ");
320 _nl_inet_ntop4(sit->ip6rd_relay_prefix, addr);
321 nl_dump_line(p, "%s\n", addr);
322 }
323
324 if (sit->sit_mask & SIT_ATTR_6RD_PREFIXLEN) {
325 nl_dump(p, " 6rd_prefixlen ");
326 nl_dump_line(p, "%d\n", sit->ip6rd_prefixlen);
327 }
328
329 if (sit->sit_mask & SIT_ATTR_6RD_RELAY_PREFIXLEN) {
330 nl_dump(p, " 6rd_relay_prefixlen ");
331 nl_dump_line(p, "%d\n", sit->ip6rd_relay_prefixlen);
332 }
333
334 if (sit->sit_mask & SIT_ATTR_FWMARK) {
335 nl_dump(p, " fwmark ");
336 nl_dump_line(p, "%x\n", sit->fwmark);
337 }
338}
339
340static int sit_clone(struct rtnl_link *dst, struct rtnl_link *src)
341{
342 struct sit_info *sit_dst, *sit_src = src->l_info;
343 int err;
344
345 dst->l_info = NULL;
346
347 err = rtnl_link_set_type(dst, "sit");
348 if (err < 0)
349 return err;
350
351 sit_dst = dst->l_info;
352
353 if (!sit_dst || !sit_src)
354 return -NLE_NOMEM;
355
356 memcpy(sit_dst, sit_src, sizeof(struct sit_info));
357
358 return 0;
359}
360
361static struct rtnl_link_info_ops sit_info_ops = {
362 .io_name = "sit",
363 .io_alloc = sit_alloc,
364 .io_parse = sit_parse,
365 .io_dump = {
366 [NL_DUMP_LINE] = sit_dump_line,
367 [NL_DUMP_DETAILS] = sit_dump_details,
368 },
369 .io_clone = sit_clone,
370 .io_put_attrs = sit_put_attrs,
371 .io_free = sit_free,
372};
373
374#define IS_SIT_LINK_ASSERT(link, sit) \
375 struct sit_info *sit; \
376 do { \
377 const struct rtnl_link *_link = (link); \
378 if (!_link || _link->l_info_ops != &sit_info_ops) { \
379 APPBUG("Link is not a sit link. set type \"sit\" first."); \
380 return -NLE_OPNOTSUPP; \
381 } \
382 (sit) = _link->l_info; \
383 } while (0)
384
385struct rtnl_link *rtnl_link_sit_alloc(void)
386{
387 struct rtnl_link *link;
388 int err;
389
390 link = rtnl_link_alloc();
391 if (!link)
392 return NULL;
393
394 err = rtnl_link_set_type(link, "sit");
395 if (err < 0) {
396 rtnl_link_put(link);
397 return NULL;
398 }
399
400 return link;
401}
402
403/**
404 * Check if link is a SIT link
405 * @arg link Link object
406 *
407 * @return True if link is a SIT link, otherwise false is returned.
408 */
409 int rtnl_link_is_sit(struct rtnl_link *link)
410{
411 return link->l_info_ops && !strcmp(link->l_info_ops->io_name, "sit");
412}
413
414/**
415 * Create a new sit tunnel device
416 * @arg sock netlink socket
417 * @arg name name of the tunnel device
418 *
419 * Creates a new sit tunnel device in the kernel
420 * @return 0 on success or a negative error code
421 */
422 int rtnl_link_sit_add(struct nl_sock *sk, const char *name)
423{
424 struct rtnl_link *link;
425 int err;
426
427 link = rtnl_link_sit_alloc();
428 if (!link)
429 return -NLE_NOMEM;
430
431 if(name)
432 rtnl_link_set_name(link, name);
433
434 err = rtnl_link_add(sk, link, NLM_F_CREATE);
435 rtnl_link_put(link);
436
437 return err;
438}
439
440/**
441 * Set SIT tunnel interface index
442 * @arg link Link object
443 * @arg index interface index
444 *
445 * @return 0 on success or a negative error code
446 */
447 int rtnl_link_sit_set_link(struct rtnl_link *link, uint32_t index)
448{
449 IS_SIT_LINK_ASSERT(link, sit);
450
451 sit->link = index;
452 sit->sit_mask |= SIT_ATTR_LINK;
453
454 return 0;
455}
456
457/**
458 * Get SIT tunnel interface index
459 * @arg link Link object
460 *
461 * @return interface index value
462 */
463uint32_t rtnl_link_sit_get_link(struct rtnl_link *link)
464{
465 IS_SIT_LINK_ASSERT(link, sit);
466
467 return sit->link;
468}
469
470/**
471 * Set SIT tunnel local address
472 * @arg link Link object
473 * @arg addr local address
474 *
475 * @return 0 on success or a negative error code
476 */
477 int rtnl_link_sit_set_local(struct rtnl_link *link, uint32_t addr)
478{
479 IS_SIT_LINK_ASSERT(link, sit);
480
481 sit->local = addr;
482 sit->sit_mask |= SIT_ATTR_LOCAL;
483
484 return 0;
485}
486
487/**
488 * Get SIT tunnel local address
489 * @arg link Link object
490 *
491 * @return local address value
492 */
493uint32_t rtnl_link_sit_get_local(struct rtnl_link *link)
494{
495 IS_SIT_LINK_ASSERT(link, sit);
496
497 return sit->local;
498}
499
500/**
501 * Set SIT tunnel remote address
502 * @arg link Link object
503 * @arg remote remote address
504 *
505 * @return 0 on success or a negative error code
506 */
507 int rtnl_link_sit_set_remote(struct rtnl_link *link, uint32_t addr)
508{
509 IS_SIT_LINK_ASSERT(link, sit);
510
511 sit->remote = addr;
512 sit->sit_mask |= SIT_ATTR_REMOTE;
513
514 return 0;
515}
516
517/**
518 * Get SIT tunnel remote address
519 * @arg link Link object
520 *
521 * @return remote address
522 */
523uint32_t rtnl_link_sit_get_remote(struct rtnl_link *link)
524{
525 IS_SIT_LINK_ASSERT(link, sit);
526
527 return sit->remote;
528}
529
530/**
531 * Set SIT tunnel ttl
532 * @arg link Link object
533 * @arg ttl tunnel ttl
534 *
535 * @return 0 on success or a negative error code
536 */
537 int rtnl_link_sit_set_ttl(struct rtnl_link *link, uint8_t ttl)
538{
539 IS_SIT_LINK_ASSERT(link, sit);
540
541 sit->ttl = ttl;
542 sit->sit_mask |= SIT_ATTR_TTL;
543
544 return 0;
545}
546
547/**
548 * Get SIT tunnel ttl
549 * @arg link Link object
550 *
551 * @return ttl value
552 */
553uint8_t rtnl_link_sit_get_ttl(struct rtnl_link *link)
554{
555 IS_SIT_LINK_ASSERT(link, sit);
556
557 return sit->ttl;
558}
559
560/**
561 * Set SIT tunnel tos
562 * @arg link Link object
563 * @arg tos tunnel tos
564 *
565 * @return 0 on success or a negative error code
566 */
567 int rtnl_link_sit_set_tos(struct rtnl_link *link, uint8_t tos)
568{
569 IS_SIT_LINK_ASSERT(link, sit);
570
571 sit->tos = tos;
572 sit->sit_mask |= SIT_ATTR_TOS;
573
574 return 0;
575}
576
577/**
578 * Get SIT tunnel tos
579 * @arg link Link object
580 *
581 * @return tos value
582 */
583uint8_t rtnl_link_sit_get_tos(struct rtnl_link *link)
584{
585 IS_SIT_LINK_ASSERT(link, sit);
586
587 return sit->tos;
588}
589
590/**
591 * Set SIT tunnel path MTU discovery
592 * @arg link Link object
593 * @arg pmtudisc path MTU discovery
594 *
595 * @return 0 on success or a negative error code
596 */
597 int rtnl_link_sit_set_pmtudisc(struct rtnl_link *link, uint8_t pmtudisc)
598{
599 IS_SIT_LINK_ASSERT(link, sit);
600
601 sit->pmtudisc = pmtudisc;
602 sit->sit_mask |= SIT_ATTR_PMTUDISC;
603
604 return 0;
605}
606
607/**
608 * Get SIT path MTU discovery
609 * @arg link Link object
610 *
611 * @return pmtudisc value
612 */
613uint8_t rtnl_link_sit_get_pmtudisc(struct rtnl_link *link)
614{
615 IS_SIT_LINK_ASSERT(link, sit);
616
617 return sit->pmtudisc;
618}
619
620/**
621 * Set SIT tunnel flags
622 * @arg link Link object
623 * @arg flags tunnel flags
624 *
625 * @return 0 on success or a negative error code
626 */
627 int rtnl_link_sit_set_flags(struct rtnl_link *link, uint16_t flags)
628{
629 IS_SIT_LINK_ASSERT(link, sit);
630
631 sit->flags = flags;
632 sit->sit_mask |= SIT_ATTR_FLAGS;
633
634 return 0;
635}
636
637/**
638 * Get SIT path flags
639 * @arg link Link object
640 *
641 * @return flags value
642 */
643uint16_t rtnl_link_sit_get_flags(struct rtnl_link *link)
644{
645 IS_SIT_LINK_ASSERT(link, sit);
646
647 return sit->flags;
648}
649
650/**
651 * Set SIT tunnel proto
652 * @arg link Link object
653 * @arg proto tunnel proto
654 *
655 * @return 0 on success or a negative error code
656 */
657 int rtnl_link_sit_set_proto(struct rtnl_link *link, uint8_t proto)
658{
659 IS_SIT_LINK_ASSERT(link, sit);
660
661 sit->proto = proto;
662 sit->sit_mask |= SIT_ATTR_PROTO;
663
664 return 0;
665}
666
667/**
668 * Get SIT proto
669 * @arg link Link object
670 *
671 * @return proto value
672 */
673uint8_t rtnl_link_sit_get_proto(struct rtnl_link *link)
674{
675 IS_SIT_LINK_ASSERT(link, sit);
676
677 return sit->proto;
678}
679
680/**
681 * Set ip6rd prefix
682 * @arg link Link object
683 * @arg prefix The IPv6 prefix
684 *
685 * @return 0 on success or an error code.
686 */
687 int rtnl_link_sit_set_ip6rd_prefix(struct rtnl_link *link, const struct in6_addr *prefix)
688{
689 IS_SIT_LINK_ASSERT(link, sit);
690
691 sit->ip6rd_prefix = *prefix;
692 sit->sit_mask |= SIT_ATTR_6RD_PREFIX;
693 return 0;
694}
695
696/**
697 * Get ip6rd prefix
698 * @arg link Link object
699 * @arg prefix The output IPv6 prefix
700 *
701 * @return 0 on success or an error code. If the property is unset,
702 * this call fails too.
703 */
704 int rtnl_link_sit_get_ip6rd_prefix(const struct rtnl_link *link, struct in6_addr *prefix)
705{
706 IS_SIT_LINK_ASSERT(link, sit);
707
708 if (!(sit->sit_mask & SIT_ATTR_6RD_PREFIX))
709 return -NLE_NOATTR;
710
711 if (prefix)
712 *prefix = sit->ip6rd_prefix;
713 return 0;
714}
715
716/**
717 * Set ip6rd prefix length
718 * @arg link Link object
719 * @arg prefixlen The IPv6 prefix length
720 *
721 * @return 0 on success or an error code.
722 */
723 int rtnl_link_sit_set_ip6rd_prefixlen(struct rtnl_link *link, uint16_t prefixlen)
724{
725 IS_SIT_LINK_ASSERT(link, sit);
726
727 sit->sit_mask |= SIT_ATTR_6RD_PREFIXLEN;
728 sit->ip6rd_prefixlen = prefixlen;
729 return 0;
730}
731
732/**
733 * Get ip6rd prefix length
734 * @arg link Link object
735 * @arg prefixlen Output pointer for the prefix length
736 *
737 * @return 0 on success or an error code. If the property is unset,
738 * this call fails.
739 */
740 int rtnl_link_sit_get_ip6rd_prefixlen(struct rtnl_link *link, uint16_t *prefixlen)
741{
742 IS_SIT_LINK_ASSERT(link, sit);
743
744 if (!(sit->sit_mask & SIT_ATTR_6RD_PREFIXLEN))
745 return -NLE_NOATTR;
746
747 if (prefixlen)
748 *prefixlen = sit->ip6rd_prefixlen;
749 return 0;
750}
751
752/**
753 * Set ip6rd relay prefix
754 * @arg link Link object
755 * @arg prefix The IPv6 prefix length
756 *
757 * @return 0 on success or an error code.
758 */
759 int rtnl_link_sit_set_ip6rd_relay_prefix(struct rtnl_link *link, uint32_t prefix)
760{
761 IS_SIT_LINK_ASSERT(link, sit);
762
763 sit->sit_mask |= SIT_ATTR_6RD_RELAY_PREFIX;
764 sit->ip6rd_relay_prefix = prefix;
765 return 0;
766}
767
768/**
769 * Get ip6rd prefix length
770 * @arg link Link object
771 * @arg prefixlen Output pointer for the prefix length
772 *
773 * @return 0 on success or an error code. If the property is unset,
774 * this call fails.
775 */
776 int rtnl_link_sit_get_ip6rd_relay_prefix(const struct rtnl_link *link, uint32_t *prefix)
777{
778 IS_SIT_LINK_ASSERT(link, sit);
779
780 if (!(sit->sit_mask & SIT_ATTR_6RD_RELAY_PREFIX))
781 return -NLE_NOATTR;
782
783 if (prefix)
784 *prefix = sit->ip6rd_relay_prefix;
785 return 0;
786}
787
788/**
789 * Set ip6rd relay prefix length
790 * @arg link Link object
791 * @arg prefixlen The IPv6 prefix length
792 *
793 * @return 0 on success or an error code.
794 */
795 int rtnl_link_sit_set_ip6rd_relay_prefixlen(struct rtnl_link *link, uint16_t prefixlen)
796{
797 IS_SIT_LINK_ASSERT(link, sit);
798
799 sit->sit_mask |= SIT_ATTR_6RD_RELAY_PREFIXLEN;
800 sit->ip6rd_relay_prefixlen = prefixlen;
801 return 0;
802}
803
804/**
805 * Get ip6rd relay prefix length
806 * @arg link Link object
807 * @arg prefixlen Output pointer for the prefix length
808 *
809 * @return 0 on success or an error code. If the property is unset,
810 * this call fails.
811 */
812 int rtnl_link_sit_get_ip6rd_relay_prefixlen(struct rtnl_link *link, uint16_t *prefixlen)
813{
814 IS_SIT_LINK_ASSERT(link, sit);
815
816 if (!(sit->sit_mask & SIT_ATTR_6RD_RELAY_PREFIX))
817 return -NLE_NOATTR;
818
819 if (prefixlen)
820 *prefixlen = sit->ip6rd_relay_prefixlen;
821 return 0;
822}
823
824/**
825 * Set SIT tunnel fwmark
826 * @arg link Link object
827 * @arg fwmark fwmark
828 *
829 * @return 0 on success or a negative error code
830 */
831 int rtnl_link_sit_set_fwmark(struct rtnl_link *link, uint32_t fwmark)
832{
833 IS_SIT_LINK_ASSERT(link, sit);
834
835 sit->fwmark = fwmark;
836 sit->sit_mask |= SIT_ATTR_FWMARK;
837
838 return 0;
839}
840
841/**
842 * Get SIT tunnel fwmark
843 * @arg link Link object
844 * @arg fwmark addr to fill in with the fwmark
845 *
846 * @return 0 on success or a negative error code
847 */
848 int rtnl_link_sit_get_fwmark(struct rtnl_link *link, uint32_t *fwmark)
849{
850 IS_SIT_LINK_ASSERT(link, sit);
851
852 if (!(sit->sit_mask & SIT_ATTR_FWMARK))
853 return -NLE_NOATTR;
854
855 *fwmark = sit->fwmark;
856
857 return 0;
858}
859
860static void _nl_init sit_init(void)
861{
862 rtnl_link_register_info(&sit_info_ops);
863}
864
865static void _nl_exit sit_exit(void)
866{
867 rtnl_link_unregister_info(&sit_info_ops);
868}
nla_get_u32
uint32_t nla_get_u32(const struct nlattr *nla)
Return payload of 32 bit integer attribute.
Definition attr.c:714
nla_get_u16
uint16_t nla_get_u16(const struct nlattr *nla)
Return payload of 16 bit integer attribute.
Definition attr.c:664
NLA_PUT_U16
#define NLA_PUT_U16(msg, attrtype, value)
Add 16 bit integer attribute to netlink message.
Definition attr.h:219
NLA_PUT_U8
#define NLA_PUT_U8(msg, attrtype, value)
Add 8 bit integer attribute to netlink message.
Definition attr.h:201
NLA_PUT
#define NLA_PUT(msg, attrtype, attrlen, data)
Add unspecific attribute to netlink message.
Definition attr.h:166
NLA_PUT_U32
#define NLA_PUT_U32(msg, attrtype, value)
Add 32 bit integer attribute to netlink message.
Definition attr.h:237
nla_get_u8
uint8_t nla_get_u8(const struct nlattr *nla)
Return value of 8 bit integer attribute.
Definition attr.c:614
nla_memcpy
int nla_memcpy(void *dest, const struct nlattr *src, int count)
Copy attribute payload to another memory area.
Definition attr.c:355
nla_nest_start
struct nlattr * nla_nest_start(struct nl_msg *msg, int attrtype)
Start a new level of nested attributes.
Definition attr.c:974
nla_parse_nested
int nla_parse_nested(struct nlattr *tb[], int maxtype, struct nlattr *nla, const struct nla_policy *policy)
Create attribute index based on nested attribute.
Definition attr.c:1101
nla_nest_end
int nla_nest_end(struct nl_msg *msg, struct nlattr *start)
Finalize nesting of attributes.
Definition attr.c:1037
NLA_U8
@ NLA_U8
8 bit integer
Definition attr.h:35
NLA_U16
@ NLA_U16
16 bit integer
Definition attr.h:36
NLA_U32
@ NLA_U32
32 bit integer
Definition attr.h:37
rtnl_link_register_info
int rtnl_link_register_info(struct rtnl_link_info_ops *ops)
Register operations for a link info type.
Definition api.c:127
rtnl_link_unregister_info
int rtnl_link_unregister_info(struct rtnl_link_info_ops *ops)
Unregister operations for a link info type.
Definition api.c:162
rtnl_link_add
int rtnl_link_add(struct nl_sock *sk, struct rtnl_link *link, int flags)
Add virtual link.
Definition link.c:1710
rtnl_link_alloc
struct rtnl_link * rtnl_link_alloc(void)
Allocate link object.
Definition link.c:1936
rtnl_link_set_name
void rtnl_link_set_name(struct rtnl_link *link, const char *name)
Set name of link object.
Definition link.c:1964
rtnl_link_get_name
char * rtnl_link_get_name(struct rtnl_link *link)
Return name of link object.
Definition link.c:1978
rtnl_link_put
void rtnl_link_put(struct rtnl_link *link)
Release a link object reference.
Definition link.c:1945
rtnl_link_set_type
int rtnl_link_set_type(struct rtnl_link *link, const char *type)
Set type of link object.
Definition link.c:2587
rtnl_link_sit_get_proto
uint8_t rtnl_link_sit_get_proto(struct rtnl_link *link)
Get SIT proto.
Definition sit.c:673
rtnl_link_sit_set_local
int rtnl_link_sit_set_local(struct rtnl_link *link, uint32_t addr)
Set SIT tunnel local address.
Definition sit.c:477
rtnl_link_sit_set_ip6rd_relay_prefix
int rtnl_link_sit_set_ip6rd_relay_prefix(struct rtnl_link *link, uint32_t prefix)
Set ip6rd relay prefix.
Definition sit.c:759
rtnl_link_sit_set_ip6rd_prefix
int rtnl_link_sit_set_ip6rd_prefix(struct rtnl_link *link, const struct in6_addr *prefix)
Set ip6rd prefix.
Definition sit.c:687
rtnl_link_sit_set_remote
int rtnl_link_sit_set_remote(struct rtnl_link *link, uint32_t addr)
Set SIT tunnel remote address.
Definition sit.c:507
rtnl_link_sit_set_tos
int rtnl_link_sit_set_tos(struct rtnl_link *link, uint8_t tos)
Set SIT tunnel tos.
Definition sit.c:567
rtnl_link_sit_set_pmtudisc
int rtnl_link_sit_set_pmtudisc(struct rtnl_link *link, uint8_t pmtudisc)
Set SIT tunnel path MTU discovery.
Definition sit.c:597
rtnl_link_sit_set_flags
int rtnl_link_sit_set_flags(struct rtnl_link *link, uint16_t flags)
Set SIT tunnel flags.
Definition sit.c:627
rtnl_link_sit_get_ip6rd_relay_prefixlen
int rtnl_link_sit_get_ip6rd_relay_prefixlen(struct rtnl_link *link, uint16_t *prefixlen)
Get ip6rd relay prefix length.
Definition sit.c:812
rtnl_link_is_sit
int rtnl_link_is_sit(struct rtnl_link *link)
Check if link is a SIT link.
Definition sit.c:409
rtnl_link_sit_get_ip6rd_prefixlen
int rtnl_link_sit_get_ip6rd_prefixlen(struct rtnl_link *link, uint16_t *prefixlen)
Get ip6rd prefix length.
Definition sit.c:740
rtnl_link_sit_get_tos
uint8_t rtnl_link_sit_get_tos(struct rtnl_link *link)
Get SIT tunnel tos.
Definition sit.c:583
rtnl_link_sit_get_flags
uint16_t rtnl_link_sit_get_flags(struct rtnl_link *link)
Get SIT path flags.
Definition sit.c:643
rtnl_link_sit_add
int rtnl_link_sit_add(struct nl_sock *sk, const char *name)
Create a new sit tunnel device.
Definition sit.c:422
rtnl_link_sit_get_fwmark
int rtnl_link_sit_get_fwmark(struct rtnl_link *link, uint32_t *fwmark)
Get SIT tunnel fwmark.
Definition sit.c:848
rtnl_link_sit_get_ttl
uint8_t rtnl_link_sit_get_ttl(struct rtnl_link *link)
Get SIT tunnel ttl.
Definition sit.c:553
rtnl_link_sit_set_fwmark
int rtnl_link_sit_set_fwmark(struct rtnl_link *link, uint32_t fwmark)
Set SIT tunnel fwmark.
Definition sit.c:831
rtnl_link_sit_get_ip6rd_prefix
int rtnl_link_sit_get_ip6rd_prefix(const struct rtnl_link *link, struct in6_addr *prefix)
Get ip6rd prefix.
Definition sit.c:704
rtnl_link_sit_set_ip6rd_relay_prefixlen
int rtnl_link_sit_set_ip6rd_relay_prefixlen(struct rtnl_link *link, uint16_t prefixlen)
Set ip6rd relay prefix length.
Definition sit.c:795
rtnl_link_sit_set_ttl
int rtnl_link_sit_set_ttl(struct rtnl_link *link, uint8_t ttl)
Set SIT tunnel ttl.
Definition sit.c:537
rtnl_link_sit_set_link
int rtnl_link_sit_set_link(struct rtnl_link *link, uint32_t index)
Set SIT tunnel interface index.
Definition sit.c:447
rtnl_link_sit_set_ip6rd_prefixlen
int rtnl_link_sit_set_ip6rd_prefixlen(struct rtnl_link *link, uint16_t prefixlen)
Set ip6rd prefix length.
Definition sit.c:723
rtnl_link_sit_get_local
uint32_t rtnl_link_sit_get_local(struct rtnl_link *link)
Get SIT tunnel local address.
Definition sit.c:493
rtnl_link_sit_set_proto
int rtnl_link_sit_set_proto(struct rtnl_link *link, uint8_t proto)
Set SIT tunnel proto.
Definition sit.c:657
rtnl_link_sit_get_pmtudisc
uint8_t rtnl_link_sit_get_pmtudisc(struct rtnl_link *link)
Get SIT path MTU discovery.
Definition sit.c:613
rtnl_link_sit_get_ip6rd_relay_prefix
int rtnl_link_sit_get_ip6rd_relay_prefix(const struct rtnl_link *link, uint32_t *prefix)
Get ip6rd prefix length.
Definition sit.c:776
rtnl_link_sit_get_remote
uint32_t rtnl_link_sit_get_remote(struct rtnl_link *link)
Get SIT tunnel remote address.
Definition sit.c:523
rtnl_link_sit_get_link
uint32_t rtnl_link_sit_get_link(struct rtnl_link *link)
Get SIT tunnel interface index.
Definition sit.c:463
nl_dump
void nl_dump(struct nl_dump_params *params, const char *fmt,...)
Dump a formatted character string.
Definition utils.c:1015
NL_DUMP_LINE
@ NL_DUMP_LINE
Dump object briefly on one line.
Definition types.h:20
NL_DUMP_DETAILS
@ NL_DUMP_DETAILS
Dump all attributes but no statistics.
Definition types.h:21
nl_dump_params
Dumping parameters.
Definition types.h:32
nla_policy
Attribute validation policy.
Definition attr.h:66
rtnl_link_info_ops
Available operations to modules implementing a link info type.
Definition link-api.h:20
rtnl_link_info_ops::io_name
char * io_name
Name of link info type, must match name on kernel side.
Definition link-api.h:22
rtnl_link
Link object.
Definition nl-route.h:29
sit_info
Definition sit.c:49