aboutsummaryrefslogtreecommitdiffstats
path: root/extras/hicn-extra-plugin/devices/rtnetlink/netns.h
blob: 53effe5cebc3a823338ede7ad28c262dfe5c720e (plain)
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
 * Copyright (c) 2016-2019 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef NETNS_H_
#define NETNS_H_

#include <vlib/vlib.h>

#include <sys/socket.h>
#include <linux/rtnetlink.h>
#include <linux/netlink.h>
#include <net/if.h>

#include "rtnl.h"

/*include it for 'struct mpls_label'*/
#include <linux/mpls.h>
/*so far depth is fixed, looking into ways to be dynamic*/
#define MPLS_STACK_DEPTH 7

typedef struct {
  struct ifinfomsg ifi;
  u8 hwaddr[IFHWADDRLEN];
  u8 broadcast[IFHWADDRLEN];
  u8 ifname[IFNAMSIZ];
  u32 mtu;
  u32 master;
  u8 qdisc[IFNAMSIZ];
  struct rtnl_link_stats stats; //This struct is big and only comes as a response to a request
  f64 last_updated;
} ns_link_t;

typedef struct {
  struct rtmsg rtm;
  u8 dst[16];
  u8 src[16];
  u8 via[16];
  u8 prefsrc[16];
  u32 iif;
  u32 oif;
  u32 table;
  u8 gateway[16];
  u32 priority;
  struct rta_cacheinfo cacheinfo;
  struct mpls_label encap[MPLS_STACK_DEPTH];
  f64 last_updated;
} ns_route_t;

typedef struct {
  struct ifaddrmsg ifaddr;
  u8 addr[16];
  u8 local[16];
  u8 label[IFNAMSIZ];
  u8 broadcast[16];
  u8 anycast[16];
  struct ifa_cacheinfo cacheinfo;
  f64 last_updated;
} ns_addr_t;

typedef struct {
  struct ndmsg nd;
  u8 dst[16];
  u8 lladdr[IFHWADDRLEN];
  u32 probes;
  struct nda_cacheinfo cacheinfo;
  f64 last_updated;
} ns_neigh_t;

typedef struct {
  char name[RTNL_NETNS_NAMELEN + 1];
  ns_link_t  *links;
  ns_route_t *routes;
  ns_addr_t  *addresses;
  ns_neigh_t *neighbors;
} netns_t;


typedef enum {
  NETNS_TYPE_LINK,
  NETNS_TYPE_ROUTE,
  NETNS_TYPE_ADDR,
  NETNS_TYPE_NEIGH,
} netns_type_t;

//Flags used in notification functions call
#define NETNS_F_ADD    0x01
#define NETNS_F_DEL    0x02

typedef struct {
  void (*notify)(void *obj, netns_type_t type, u32 flags, uword opaque);
  uword opaque;
} netns_sub_t;

/*
 * Subscribe for events related to the given namespace.
 * When another subscriber already uses the namespace,
 * this call will not trigger updates for already
 * existing routes (This is to protect against
 * synch. Vs asynch. issues).
 */
u32 netns_open(char *name, netns_sub_t *sub);

/*
 * Retrieves the namespace structure associated with a
 * given namespace handler.
 */
netns_t *netns_getns(u32 handle);

/*
 * Terminates a subscriber session.
 */
void netns_close(u32 handle);

/*
 * Calls the callback associated with the handle
 * for all existing objects with the flags
 * set to (del?NETNS_F_DEL:NETNS_F_ADD).
 */
void netns_callme(u32 handle, char del);

/*
 * netns struct format functions.
 * Taking the struct as single argument.
 */
u8 *format_ns_neigh(u8 *s, va_list *args);
u8 *format_ns_addr(u8 *s, va_list *args);
u8 *format_ns_route(u8 *s, va_list *args);
u8 *format_ns_link(u8 *s, va_list *args);

u8 *format_ns_object(u8 *s, va_list *args);
u8 *format_ns_flags(u8 *s, va_list *args);

#endif