rtnl.h revision 4c047107
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 <linux/netlink.h>
20#include <vppinfra/clib.h>
21
22typedef enum {
23  RTNL_ERR_UNKNOWN,
24} rtnl_error_t;
25
26#define RTNL_NETNS_NAMELEN 31
27
28/*
29 * RTNL stream implements an RTNL overlay
30 * for receiving continuous updates for a given namespace.
31 * When the stream is initially opened, dump requests are sent
32 * in order to retrieve the original state.
33 * handle_error is called any time synchronization cannot be
34 * achieved. When called, state is reset to its original state and
35 * new dump requests are sent.
36 */
37
38typedef struct rtnl_stream_s {
39  char name[RTNL_NETNS_NAMELEN + 1];
40  void (*recv_message)(struct nlmsghdr *hdr, uword opaque);
41  void (*error)(rtnl_error_t err, uword opaque);
42  uword opaque;
43} rtnl_stream_t;
44
45u32 rtnl_stream_open(rtnl_stream_t *template);
46void rtnl_stream_close(u32 handle);
47
48/*
49 * Executes a function in a synchronously executed thread in the
50 * given namespace.
51 * Returns 0 on success, and -errno on error.
52 */
53int rtnl_exec_in_namespace(u32 handle, void *(*fn)(void *), void *arg, void **ret);
54int rtnl_exec_in_namespace_by_name(char *nsname, void *(*fn)(void *), void *arg, void **ret);
55
56#endif
57