|
FD.io VPP
v21.06-3-gbb25fbf28
Vector Packet Processing
|
Go to the documentation of this file.
20 #include <sys/socket.h>
24 #include <netlink/route/link/vlan.h>
63 #define LCP_ITF_PAIR_DBG(...) \
64 vlib_log_notice (lcp_itf_pair_logger, __VA_ARGS__);
66 #define LCP_ITF_PAIR_INFO(...) \
67 vlib_log_notice (lcp_itf_pair_logger, __VA_ARGS__);
81 s =
format (s,
" <no-phy-if>");
87 s =
format (s,
" <no-host-if>");
126 ns ? (
char *) ns :
"<unset>");
128 if (phy_sw_if_index == ~0)
161 u32 phy_sw_if_index,
u8 *ns)
173 [
AF_IP4] =
"linux-cp-xc-ip4",
174 [
AF_IP6] =
"linux-cp-xc-ip6",
177 [
AF_IP4] =
"linux-cp-xc-l3-ip4",
178 [
AF_IP6] =
"linux-cp-xc-l3-ip6",
241 return VNET_API_ERROR_VALUE_EXIST;
332 struct rtnl_link *link;
336 sk = nl_socket_alloc ();
337 if ((err = nl_connect (sk, NETLINK_ROUTE)) < 0)
340 link = rtnl_link_vlan_alloc ();
342 rtnl_link_set_link (link, parent);
343 rtnl_link_set_name (link,
name);
345 rtnl_link_vlan_set_id (link, vlan);
347 if ((err = rtnl_link_add (sk, link, NLM_F_CREATE)) < 0)
350 rtnl_link_put (link);
359 struct rtnl_link *link;
363 sk = nl_socket_alloc ();
364 if ((err = nl_connect (sk, NETLINK_ROUTE)) < 0)
367 link = rtnl_link_alloc ();
368 rtnl_link_set_name (link,
name);
370 if ((err = rtnl_link_delete (sk, link)) < 0)
373 rtnl_link_put (link);
389 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
437 u32 host_sw_if_index;
467 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
503 host = phy = ns = default_ns = NULL;
509 if (
unformat (input,
"pair %s %s %s", &phy, &
host, &ns))
516 "linux-cp IF namespace must"
517 " be less than %d characters",
537 else if (
unformat (input,
"default netns %v", &default_ns))
543 "linux-cp default namespace must"
544 " be less than %d characters",
548 else if (
unformat (input,
"interface-auto-create"))
603 char ns_path[256] =
"/proc/self/ns/net";
606 snprintf (ns_path,
sizeof (ns_path) - 1,
"/var/run/netns/%s", ns_name);
608 return open (ns_path, O_RDONLY);
614 int curr_ns_fd, vif_ns_fd;
616 curr_ns_fd = vif_ns_fd = -1;
622 curr_ns_fd = open (
"/proc/self/ns/net", O_RDONLY);
623 ns_path =
format (0,
"/var/run/netns/%s%c", (
char *) ns, 0);
624 vif_ns_fd = open ((
char *) ns_path, O_RDONLY);
626 setns (vif_ns_fd, CLONE_NEWNET);
634 if (curr_ns_fd != -1)
636 setns (curr_ns_fd, CLONE_NEWNET);
644 u32 *host_sw_if_indexp)
648 u32 vif_index = 0, host_sw_if_index;
653 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
656 return VNET_API_ERROR_INVALID_ARGUMENT;
667 if (ns == 0 || ns[0] == 0)
674 int orig_ns_fd, ns_fd;
687 orig_ns_fd = ns_fd = -1;
690 if (ns && ns[0] != 0)
694 if (orig_ns_fd == -1 || ns_fd == -1)
697 setns (ns_fd, CLONE_NEWNET);
708 (
const char *) host_if_name);
710 if (!err && -1 != ns_fd)
729 if (orig_ns_fd != -1)
731 setns (orig_ns_fd, CLONE_NEWNET);
738 return VNET_API_ERROR_INVALID_ARGUMENT;
748 .host_if_name = host_if_name,
767 if (ns && ns[0] != 0)
819 lcp_itf_pair_add (host_sw_if_index, phy_sw_if_index, host_if_name, vif_index,
825 host_sw_if_index, host_if_name);
827 if (host_sw_if_indexp)
828 *host_sw_if_indexp = host_sw_if_index;
893 uword *event_data = 0;
920 .name =
"linux-cp-itf-process",
1011 .runs_after =
VLIB_INITS (
"vnet_interface_init",
"tcp_init",
"udp_init"),
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
#define LCP_ITF_PAIR_INFO(...)
void udp_punt_unknown(vlib_main_t *vm, u8 is_ip4, u8 is_add)
void ip_feature_enable_disable(ip_address_family_t af, ip_sub_address_family_t safi, ip_feature_location_t loc, const char *feature_name, u32 sw_if_index, int enable, void *feature_config, u32 n_feature_config_bytes)
struct lcp_itf_pair_names_t_ lcp_itf_pair_names_t
static int lcp_itf_get_ns_fd(char *ns_name)
static u32 vlib_num_workers()
static clib_error_t * lcp_itf_pair_init(vlib_main_t *vm)
const char * lcp_itf_l3_feat_names[N_LCP_ITF_HOST][N_AF]
static int lcp_validate_if_name(u8 *name)
u8 * format_lcp_itf_pair(u8 *s, va_list *args)
static uword lcp_itf_pair_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
static walk_rc_t lcp_itf_pair_walk_sweep(index_t lipi, void *arg)
void ip6_punt_redirect_del(u32 rx_sw_if_index)
index_t lcp_itf_pair_find_by_vif(u32 vif_index)
Find a interface-pair object from the host interface.
const ip46_address_t zero_addr
#include <vnet/feature/feature.h>
adj_index_t adj_nbr_add_or_lock(fib_protocol_t nh_proto, vnet_link_t link_type, const ip46_address_t *nh_addr, u32 sw_if_index)
Neighbour Adjacency sub-type.
void tap_create_if(vlib_main_t *vm, tap_create_if_args_t *args)
static uword * vlib_process_wait_for_event(vlib_main_t *vm)
u8 * lcp_get_default_ns(void)
static clib_error_t * lcp_itf_pair_config(vlib_main_t *vm, unformat_input_t *input)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
static vnet_sw_interface_t * vnet_get_sw_interface_or_null(vnet_main_t *vnm, u32 sw_if_index)
clib_error_t * vnet_netlink_set_link_netns(int ifindex, int netns_fd, char *new_ifname)
int vnet_create_sub_interface(u32 sw_if_index, u32 id, u32 flags, u16 inner_vlan_id, u16 outer_vlan_id, u32 *sub_sw_if_index)
#define ETHERNET_INTERFACE_FLAG_STATUS_L3
vlib_log_class_t vlib_log_register_class(char *class, char *subclass)
adj_index_t adj_mcast_add_or_lock(fib_protocol_t proto, vnet_link_t link_type, u32 sw_if_index)
Mcast Adjacency.
u32 lcp_itf_num_pairs(void)
void lcp_set_auto_intf(u8 is_auto)
manage interface auto creation
static vlib_punt_hdl_t punt_hdl
#define clib_error_return(e, args...)
void adj_unlock(adj_index_t adj_index)
Release a reference counting lock on the adjacency.
unsigned int if_nametoindex(const char *ifname)
#define FOR_EACH_IP_ADDRESS_FAMILY(_af)
static vlib_node_registration_t lcp_itf_pair_process_node
(constructor) VLIB_REGISTER_NODE (lcp_itf_pair_process_node)
static void lcp_itf_pair_delete_by_index(index_t lipi)
#define pool_put(P, E)
Free an object E in pool P.
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
@ VNET_HW_INTERFACE_FLAG_LINK_UP
VNET_HW_INTERFACE_LINK_UP_DOWN_FUNCTION(lcp_itf_pair_link_up_down)
int lcp_itf_pair_add(u32 host_sw_if_index, u32 phy_sw_if_index, u8 *host_name, u32 host_index, lip_host_type_t host_type, u8 *ns)
Create an interface-pair.
int vlib_punt_register(vlib_punt_hdl_t client, vlib_punt_reason_t reason, const char *node_name)
Register a node to receive particular punted buffers.
dpo_proto_t frp_proto
The protocol of the address below.
int lcp_itf_pair_add_sub(u32 vif, u8 *host_if_name, u32 sub_sw_if_index, u32 phy_sw_if_index, u8 *ns)
lcp_itf_phy_adj_t lip_phy_adjs
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
#define vec_cmp(v1, v2)
Compare two vectors (only applicable to vectors of signed numbers).
static clib_error_t * lcp_itf_phy_add(vnet_main_t *vnm, u32 sw_if_index, u32 is_create)
adj_index_t adj_index[N_AF]
@ FIB_ROUTE_PATH_DVR
A path that resolves via a DVR DPO.
#define VLIB_EARLY_CONFIG_FUNCTION(x, n,...)
import vnet interface_types api
index_t * lip_db_by_phy
Retreive the pair in the DP.
#define hash_set(h, key, value)
lcp_itf_pair_t * lcp_itf_pair_get(u32 index)
Get an interface-pair object from its VPP index.
struct vnet_sub_interface_t::@368 eth
virtio_main_t virtio_main
ethernet_interface_t * interfaces
static uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
Return the first event type which has occurred and a vector of per-event data of that type,...
static_always_inline void mac_address_copy(mac_address_t *dst, const mac_address_t *src)
walk_rc_t(* lcp_itf_pair_walk_cb_t)(index_t index, void *ctx)
Callback function invoked during a walk of all interface-pairs.
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
void vnet_sw_interface_admin_up(vnet_main_t *vnm, u32 sw_if_index)
int lcp_itf_pair_create(u32 phy_sw_if_index, u8 *host_if_name, lip_host_type_t host_if_type, u8 *ns, u32 *host_sw_if_indexp)
Create an interface-pair from PHY sw_if_index and tap name.
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
static vlib_log_class_t lcp_itf_pair_logger
#define vec_dup(V)
Return copy of vector (no header, no alignment)
clib_error_t * vnet_netlink_set_link_state(int ifindex, int up)
vnet_main_t * vnet_get_main(void)
int __clib_weak lcp_nl_drain_messages(void)
int lcp_itf_pair_del(u32 phy_sw_if_index)
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
static uword vnet_sw_interface_is_sub(vnet_main_t *vnm, u32 sw_if_index)
int tap_delete_if(vlib_main_t *vm, u32 sw_if_index)
static void lcp_itf_set_vif_link_state(u32 vif_index, u8 up, u8 *ns)
int lcp_itf_pair_replace_begin(void)
Begin and End the replace process.
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
void tcp_punt_unknown(vlib_main_t *vm, u8 is_ip4, u8 is_add)
VNET_SW_INTERFACE_ADD_DEL_FUNCTION(lcp_itf_phy_add)
struct _vlib_node_registration vlib_node_registration_t
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
static lcp_itf_pair_names_t * lipn_names
static walk_rc_t lcp_itf_pair_walk_mark(index_t lipi, void *ctx)
const fib_route_path_flags_t lcp_itf_route_path_flags[N_LCP_ITF_HOST]
static clib_error_t * lcp_itf_pair_link_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
lip_host_type_t lip_host_type
static void lcp_itf_set_adjs(lcp_itf_pair_t *lip)
static uword vnet_sw_if_index_is_api_valid(u32 sw_if_index)
int lcp_itf_pair_delete(u32 phy_sw_if_index)
Delete a LCP_ITF_PAIR.
void ip6_punt_redirect_add_paths(u32 rx_sw_if_index, fib_route_path_t *paths)
description ARP replies copied to host
#define clib_strnlen(s, m)
#define vec_free(V)
Free vector's memory (no header).
void ip4_punt_redirect_add_paths(u32 rx_sw_if_index, fib_route_path_t *paths)
fib_route_path_flags_t frp_flags
flags on the path
#define pool_foreach_index(i, v)
ethernet_main_t ethernet_main
format_function_t format_vnet_sw_if_index_name
description fragment has unexpected format
#define vec_validate_init_empty(V, I, INIT)
Make sure vector is long enough for given index and initialize empty space (no header,...
@ FIB_ROUTE_PATH_FLAG_NONE
#define VLIB_INIT_FUNCTION(x)
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
int tap_set_carrier(u32 hw_if_index, u32 carrier_up)
A representation of a path as described by a route producer.
static vnet_hw_interface_t * vnet_get_hw_interface_or_null(vnet_main_t *vnm, u32 hw_if_index)
#define vec_foreach(var, vec)
Vector iterator.
static uword pool_elts(void *v)
Number of active elements in a pool.
struct lcp_itf_pair_sweep_ctx_t_ lcp_itf_pair_sweep_ctx_t
int vlib_punt_hdl_t
Typedef for a client handle.
int vnet_feature_enable_disable(const char *arc_name, const char *node_name, u32 sw_if_index, int enable_disable, void *feature_config, u32 n_feature_config_bytes)
static vlib_main_t * vlib_get_main(void)
static uword * lip_db_by_vif
DBs of interface-pair objects:
void ip4_punt_redirect_del(u32 rx_sw_if_index)
vnet_interface_output_runtime_t * rt
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
static index_t lcp_itf_pair_find_by_phy(u32 phy_sw_if_index)
static clib_error_t * lcp_netlink_add_link_vlan(int parent, u32 vlan, const char *name)
void lcp_itf_pair_walk(lcp_itf_pair_walk_cb_t cb, void *ctx)
Walk/visit each of the interface pairs.
enum fib_route_path_flags_t_ fib_route_path_flags_t
Path flags from the control plane.
lcp_itf_pair_t * lcp_itf_pair_pool
Pool of LIP objects.
static f64 vlib_time_now(vlib_main_t *vm)
vlib_punt_hdl_t vlib_punt_client_register(const char *who)
Register a new clinet.
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
void lcp_itf_pair_show(u32 phy_sw_if_index)
vl_api_interface_index_t sw_if_index
ethernet_interface_address_t address
int lcp_itf_pair_replace_end(void)
enum walk_rc_t_ walk_rc_t
Walk return code.
static ip_adjacency_t * adj_get(adj_index_t adj_index)
Get a pointer to an adjacency object from its index.
vlib_punt_reason_t ipsec_punt_reason[IPSEC_PUNT_N_REASONS]
int lcp_set_default_ns(u8 *ns)
Get/Set the default namespace for LCP host taps.
static walk_rc_t lcp_itf_pair_walk_show_cb(index_t api, void *ctx)
int vnet_delete_sub_interface(u32 sw_if_index)
mac_address_t host_mac_addr
format_function_t format_vnet_sw_interface_name
enum ip_address_family_t_ ip_address_family_t
int tap_set_speed(u32 hw_if_index, u32 speed)
static void lcp_itf_unset_adjs(lcp_itf_pair_t *lip)
#define VLIB_REGISTER_NODE(x,...)
vl_api_wireguard_peer_flags_t flags
static clib_error_t * lcp_netlink_del_link(const char *name)