]>
git.proxmox.com Git - mirror_ovs.git/blob - lib/netnsid.h
2 * Copyright (c) 2017 Red Hat Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 #ifdef HAVE_LINUX_NET_NAMESPACE_H
23 #include <linux/net_namespace.h>
27 * The network namespace ID is a positive number that identifies the namespace
28 * which the netlink message was sent. It is used to identify if a received
29 * message belongs to a port attached to the bridge.
31 * There are three port states listed below:
32 * UNSET: A port in this state means that it could be either in same network
33 * namespace as the daemon (LOCAL) or in another namespace (ID). Any operation
34 * on a port in this state that requires the ID will trigger a query to the
35 * kernel to find out in which namespace the port currently is.
37 * LOCAL: A port in this state means that it is in the same network namespace
40 * ID: A port that is not LOCAL and not UNSET has a valid positive (zero
41 * included) remote namespace ID.
43 * Possible state changes:
45 * Initial port's state: UNSET.
47 * UNSET -> LOCAL: The daemon queries the kernel and finds that it's in the
48 * same network namespace as the daemon or the API is not available (older
51 * LOCAL -> UNSET: The kernel sends a deregistering netlink message which
52 * unsets the port. It happens when the port is removed (or moved to another
55 * UNSET -> ID: The daemon queries the kernel and finds that the port is
56 * in a specific network namespace with ID assigned.
58 * ID -> UNSET: When it receives a deregistering netlink message from that
59 * namespace indicating the device is being removed (or moved to another
63 #ifdef NETNSA_NSID_NOT_ASSIGNED
64 #define NETNSID_LOCAL NETNSA_NSID_NOT_ASSIGNED
66 #define NETNSID_LOCAL -1
68 #define NETNSID_UNSET (NETNSID_LOCAL - 1)
71 static inline void netnsid_set_local(int *nsid
);
72 static inline bool netnsid_is_local(int nsid
);
73 static inline void netnsid_unset(int *nsid
);
74 static inline bool netnsid_is_unset(int nsid
);
75 static inline bool netnsid_is_remote(int nsid
);
76 static inline void netnsid_set(int *nsid
, int id
);
77 static inline bool netnsid_eq(int nsid1
, int nsid2
);
81 netnsid_set_local(int *nsid
)
83 *nsid
= NETNSID_LOCAL
;
87 netnsid_is_local(int nsid
)
89 return nsid
== NETNSID_LOCAL
;
93 netnsid_unset(int *nsid
)
95 *nsid
= NETNSID_UNSET
;
99 netnsid_is_unset(int nsid
)
101 return nsid
== NETNSID_UNSET
;
105 netnsid_is_remote(int nsid
)
107 if (netnsid_is_unset(nsid
) || netnsid_is_local(nsid
)) {
115 netnsid_set(int *nsid
, int id
)
117 /* The kernel only sends positive numbers for valid IDs. */
118 if (id
!= NETNSID_LOCAL
) {
126 netnsid_eq(int nsid1
, int nsid2
)
128 if (netnsid_is_unset(nsid1
) || netnsid_is_unset(nsid2
)) {
132 if (nsid1
== nsid2
) {