rtnl.h revision 83ddb4c4
1/*
2 * Copyright (c) 2016 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef RTNL_H_
17#define RTNL_H_
18
19#include <vlib/vlib.h>
20
21#include <linux/netlink.h>
22#include <vppinfra/clib.h>
23
24typedef enum {
25  RTNL_ERR_UNKNOWN,
26} rtnl_error_t;
27
28#define RTNL_NETNS_NAMELEN 128
29
30/*
31 * RTNL stream implements an RTNL overlay
32 * for receiving continuous updates for a given namespace.
33 * When the stream is initially opened, dump requests are sent
34 * in order to retrieve the original state.
35 * handle_error is called any time synchronization cannot be
36 * achieved. When called, state is reset to its original state and
37 * new dump requests are sent.
38 */
39
40typedef struct rtnl_stream_s {
41  char name[RTNL_NETNS_NAMELEN + 1];
42  void (*recv_message)(struct nlmsghdr *hdr, uword opaque);
43  void (*error)(rtnl_error_t err, uword opaque);
44  uword opaque;
45} rtnl_stream_t;
46
47u32 rtnl_stream_open(rtnl_stream_t *template);
48void rtnl_stream_close(u32 handle);
49
50/*
51 * Executes a function in a synchronously executed thread in the
52 * given namespace.
53 * Returns 0 on success, and -errno on error.
54 */
55int rtnl_exec_in_namespace(u32 handle, void *(*fn)(void *), void *arg, void **ret);
56int rtnl_exec_in_namespace_by_name(char *nsname, void *(*fn)(void *), void *arg, void **ret);
57
58u8 *format_rtnl_nsname2path(u8 *s, va_list *args);
59
60#endif
61