Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

working l2vlan sub-interface #49

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/interfaces/src/plugin/api/interfaces/interface/load.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <linux/if.h>
#include <srpc.h>
#include <string.h>

int interfaces_interface_load_name(interfaces_ctx_t* ctx, interfaces_interface_hash_element_t** element, struct rtnl_link* link)
{
Expand Down Expand Up @@ -78,3 +79,27 @@ int interfaces_interface_load_enabled(interfaces_ctx_t* ctx, interfaces_interfac

return error;
}

int interfaces_interface_load_parent_interface(interfaces_ctx_t* ctx, interfaces_interface_hash_element_t** element, struct rtnl_link* link)
{
int error = 0;

const char* nl_if_name = NULL;

nl_if_name = rtnl_link_get_name(link);
char *junk = strchr(nl_if_name, '.');
if(junk) {
char dev_name[strlen(nl_if_name) - strlen(junk)];
memcpy(dev_name, nl_if_name, sizeof dev_name);
SRPC_SAFE_CALL_ERR(error, interfaces_interface_hash_element_set_parent_interface(element, dev_name), error_out);
}

goto out;

error_out:
error = -1;

out:

return error;
}
3 changes: 2 additions & 1 deletion src/interfaces/src/plugin/api/interfaces/interface/load.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
int interfaces_interface_load_name(interfaces_ctx_t* ctx, interfaces_interface_hash_element_t** element, struct rtnl_link* link);
int interfaces_interface_load_type(interfaces_ctx_t* ctx, interfaces_interface_hash_element_t** element, struct rtnl_link* link);
int interfaces_interface_load_enabled(interfaces_ctx_t* ctx, interfaces_interface_hash_element_t** element, struct rtnl_link* link);
int interfaces_interface_load_parent_interface(interfaces_ctx_t* ctx, interfaces_interface_hash_element_t** element, struct rtnl_link* link);

#endif // INTERFACES_PLUGIN_API_INTERFACES_INTERFACE_LOAD_H
#endif // INTERFACES_PLUGIN_API_INTERFACES_INTERFACE_LOAD_H
5 changes: 4 additions & 1 deletion src/interfaces/src/plugin/api/interfaces/load.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ int interfaces_load_interface(interfaces_ctx_t* ctx, interfaces_interface_hash_e
SRPC_SAFE_CALL_PTR(new_element, interfaces_interface_hash_element_new(), error_out);
element_added = 0;

// load parent interface
SRPC_SAFE_CALL_ERR(error, interfaces_interface_load_parent_interface(ctx, &new_element, link_iter), error_out);

// load interface data
SRPC_SAFE_CALL_ERR(error, interfaces_interface_load_name(ctx, &new_element, link_iter), error_out);
SRPC_SAFE_CALL_ERR(error, interfaces_interface_load_type(ctx, &new_element, link_iter), error_out);
Expand Down Expand Up @@ -131,4 +134,4 @@ int interfaces_load_interface(interfaces_ctx_t* ctx, interfaces_interface_hash_e
// address and neighbor caches should be freed by their functions (_load_address and _load_neighbor)

return error;
}
}
9 changes: 5 additions & 4 deletions src/interfaces/src/plugin/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ extern const char* const PLUGIN_NAME;
#define INTERFACES_INTERFACES_STATE_INTERFACE_IPV4_NEIGHBOR_LINK_LAYER_ADDRESS_YANG_PATH INTERFACES_INTERFACES_STATE_INTERFACE_IPV4_NEIGHBOR_YANG_PATH "/link-layer-address"
#define INTERFACES_INTERFACES_STATE_INTERFACE_IPV4_NEIGHBOR_ORIGIN_YANG_PATH INTERFACES_INTERFACES_STATE_INTERFACE_IPV4_NEIGHBOR_YANG_PATH "/origin"
#define INTERFACES_INTERFACES_STATE_INTERFACE_IPV4_NEIGHBOR_YANG_PATH INTERFACES_INTERFACES_STATE_INTERFACE_IPV4_YANG_PATH "/neighbor"
#define INTERFACES_INTERFACES_STATE_INTERFACE_IPV4_YANG_PATH INTERFACES_INTERFACES_STATE_INTERFACE_YANG_PATH "/ipv4"
#define INTERFACES_INTERFACES_STATE_INTERFACE_IPV4_YANG_PATH INTERFACES_INTERFACES_STATE_INTERFACE_YANG_PATH "/ietf-ip:ipv4"
#define INTERFACES_INTERFACES_STATE_INTERFACE_IPV6_FORWARDING_YANG_PATH INTERFACES_INTERFACES_STATE_INTERFACE_IPV6_YANG_PATH "/forwarding"
#define INTERFACES_INTERFACES_STATE_INTERFACE_IPV6_MTU_YANG_PATH INTERFACES_INTERFACES_STATE_INTERFACE_IPV6_YANG_PATH "/mtu"
#define INTERFACES_INTERFACES_STATE_INTERFACE_IPV6_ADDRESS_IP_YANG_PATH INTERFACES_INTERFACES_STATE_INTERFACE_IPV6_ADDRESS_YANG_PATH "/ip"
Expand All @@ -73,8 +73,9 @@ extern const char* const PLUGIN_NAME;
#define INTERFACES_INTERFACES_STATE_INTERFACE_IPV6_NEIGHBOR_IS_ROUTER_YANG_PATH INTERFACES_INTERFACES_STATE_INTERFACE_IPV6_NEIGHBOR_YANG_PATH "/is-router"
#define INTERFACES_INTERFACES_STATE_INTERFACE_IPV6_NEIGHBOR_STATE_YANG_PATH INTERFACES_INTERFACES_STATE_INTERFACE_IPV6_NEIGHBOR_YANG_PATH "/state"
#define INTERFACES_INTERFACES_STATE_INTERFACE_IPV6_NEIGHBOR_YANG_PATH INTERFACES_INTERFACES_STATE_INTERFACE_IPV6_YANG_PATH "/neighbor"
#define INTERFACES_INTERFACES_STATE_INTERFACE_IPV6_YANG_PATH INTERFACES_INTERFACES_STATE_INTERFACE_YANG_PATH "/ipv6"
#define INTERFACES_INTERFACES_STATE_INTERFACE_IPV6_YANG_PATH INTERFACES_INTERFACES_STATE_INTERFACE_YANG_PATH "/ietf-ip:ipv6"
#define INTERFACES_INTERFACES_STATE_INTERFACE_YANG_PATH INTERFACES_INTERFACES_STATE_YANG_PATH "/interface"
#define INTERFACES_INTERFACES_STATE_INTERFACE_PARENT_INTERFACE_YANG_PATH INTERFACES_INTERFACES_INTERFACE_YANG_PATH "/ietf-if-extensions:parent-interface"
#define INTERFACES_INTERFACES_STATE_YANG_PATH "/ietf-interfaces:interfaces-state"
#define INTERFACES_INTERFACES_INTERFACE_NAME_YANG_PATH INTERFACES_INTERFACES_INTERFACE_YANG_PATH "/name"
#define INTERFACES_INTERFACES_INTERFACE_DESCRIPTION_YANG_PATH INTERFACES_INTERFACES_INTERFACE_YANG_PATH "/description"
Expand Down Expand Up @@ -129,7 +130,7 @@ extern const char* const PLUGIN_NAME;
#define INTERFACES_INTERFACES_INTERFACE_LOOPBACK_YANG_PATH INTERFACES_INTERFACES_INTERFACE_YANG_PATH "/loopback"
#define INTERFACES_INTERFACES_INTERFACE_MAX_FRAME_SIZE_YANG_PATH INTERFACES_INTERFACES_INTERFACE_YANG_PATH "/max-frame-size"
#define INTERFACES_INTERFACES_INTERFACE_FORWARDING_MODE_YANG_PATH INTERFACES_INTERFACES_INTERFACE_YANG_PATH "/forwarding-mode"
#define INTERFACES_INTERFACES_INTERFACE_PARENT_INTERFACE_YANG_PATH INTERFACES_INTERFACES_INTERFACE_YANG_PATH "/parent-interface"
#define INTERFACES_INTERFACES_INTERFACE_PARENT_INTERFACE_YANG_PATH INTERFACES_INTERFACES_INTERFACE_YANG_PATH "/ietf-if-extensions:parent-interface"
#define INTERFACES_INTERFACES_INTERFACE_IPV4_ENABLED_YANG_PATH INTERFACES_INTERFACES_INTERFACE_IPV4_YANG_PATH "/enabled"
#define INTERFACES_INTERFACES_INTERFACE_IPV4_FORWARDING_YANG_PATH INTERFACES_INTERFACES_INTERFACE_IPV4_YANG_PATH "/forwarding"
#define INTERFACES_INTERFACES_INTERFACE_IPV4_MTU_YANG_PATH INTERFACES_INTERFACES_INTERFACE_IPV4_YANG_PATH "/mtu"
Expand Down Expand Up @@ -163,7 +164,7 @@ extern const char* const PLUGIN_NAME;
#define INTERFACES_INTERFACES_INTERFACE_IPV6_AUTOCONF_TEMPORARY_VALID_LIFETIME_YANG_PATH INTERFACES_INTERFACES_INTERFACE_IPV6_AUTOCONF_YANG_PATH "/temporary-valid-lifetime"
#define INTERFACES_INTERFACES_INTERFACE_IPV6_AUTOCONF_TEMPORARY_PREFERRED_LIFETIME_YANG_PATH INTERFACES_INTERFACES_INTERFACE_IPV6_AUTOCONF_YANG_PATH "/temporary-preferred-lifetime"
#define INTERFACES_INTERFACES_INTERFACE_IPV6_AUTOCONF_YANG_PATH INTERFACES_INTERFACES_INTERFACE_IPV6_YANG_PATH "/autoconf"
#define INTERFACES_INTERFACES_INTERFACE_IPV6_YANG_PATH INTERFACES_INTERFACES_INTERFACE_YANG_PATH "/ipv6"
#define INTERFACES_INTERFACES_INTERFACE_IPV6_YANG_PATH INTERFACES_INTERFACES_INTERFACE_YANG_PATH "/ietf-ip:ipv6"
#define INTERFACES_INTERFACES_INTERFACE_YANG_PATH INTERFACES_INTERFACES_YANG_PATH "/interface"
#define INTERFACES_INTERFACES_YANG_PATH "/ietf-interfaces:interfaces"

Expand Down
6 changes: 6 additions & 0 deletions src/interfaces/src/plugin/data/interfaces/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,18 @@ int interfaces_interface_hash_to_ly(const struct ly_ctx* ly_ctx, interfaces_inte
// name added via list creation
SRPC_SAFE_CALL_ERR(error, interfaces_ly_tree_create_interfaces_interface(ly_ctx, *interfaces_container_node, &interface_list_node, if_iter->interface.name), error_out);

// create ietf-if-extensions:parent-interface if required
if(strcmp(if_iter->interface.type, "iana-if-type:l2vlan") == 0) {
SRPC_SAFE_CALL_ERR(error, interfaces_ly_tree_create_interfaces_interface_parent_interface(ly_ctx, interface_list_node, if_iter->interface.parent_interface), error_out);
}

// enabled
SRPC_SAFE_CALL_ERR(error, interfaces_ly_tree_create_interfaces_interface_enabled(ly_ctx, interface_list_node, if_iter->interface.enabled ? "true" : "false"), error_out);

// type
SRPC_SAFE_CALL_ERR(error, interfaces_ly_tree_create_interfaces_interface_type(ly_ctx, interface_list_node, if_iter->interface.type), error_out);


// IPv4
SRPC_SAFE_CALL_ERR(error, interfaces_ly_tree_create_interfaces_interface_ipv4(ly_ctx, interface_list_node, &ipv4_container_node), error_out);

Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/src/plugin/ly_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ int interfaces_ly_tree_create_interfaces_interface_ipv4_enabled(const struct ly_

int interfaces_ly_tree_create_interfaces_interface_parent_interface(const struct ly_ctx* ly_ctx, struct lyd_node* interface_node, const char* parent_interface)
{
return srpc_ly_tree_create_leaf(ly_ctx, interface_node, NULL, "parent-interface", parent_interface);
return srpc_ly_tree_create_leaf(ly_ctx, interface_node, NULL, "ietf-if-extensions:parent-interface", parent_interface);
}

int interfaces_ly_tree_create_interfaces_interface_forwarding_mode(const struct ly_ctx* ly_ctx, struct lyd_node* interface_node, const char* forwarding_mode)
Expand Down