aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/ietf
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/ietf')
-rw-r--r--src/plugins/ietf/ietf_interface.c194
-rw-r--r--src/plugins/ietf/ietf_interface.h25
-rw-r--r--src/plugins/ietf/ietf_nat.c54
-rw-r--r--src/plugins/ietf/ietf_nat.h25
4 files changed, 94 insertions, 204 deletions
diff --git a/src/plugins/ietf/ietf_interface.c b/src/plugins/ietf/ietf_interface.c
index 922c84f..0f8c37e 100644
--- a/src/plugins/ietf/ietf_interface.c
+++ b/src/plugins/ietf/ietf_interface.c
@@ -15,33 +15,12 @@
#include <stdio.h>
#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include "ietf_interface.h"
+#include "../sc_model.h"
+#include "../sys_util.h"
-#include "sc_vpp_interface.h"
-#include "sc_vpp_ip.h"
-
-/**
- * @brief Helper function for converting netmask (ex: 255.255.255.0)
- * to prefix length (ex: 24).
- */
-static uint8_t
-netmask_to_prefix(const char *netmask)
-{
- in_addr_t n = 0;
- uint8_t i = 0;
-
- inet_pton(AF_INET, netmask, &n);
-
- while (n > 0) {
- n = n >> 1;
- i++;
- }
-
- return i;
-}
+#include <scvpp/interface.h>
+#include <scvpp/ip.h>
/**
* @brief Callback to be called by any config change of
@@ -51,6 +30,7 @@ static int
ietf_interface_enable_disable_cb(sr_session_ctx_t *session, const char *xpath,
sr_notif_event_t event, void *private_ctx)
{
+ UNUSED(private_ctx);
char *if_name = NULL;
sr_change_iter_t *iter = NULL;
sr_change_oper_t op = SR_OP_CREATED;
@@ -60,22 +40,22 @@ ietf_interface_enable_disable_cb(sr_session_ctx_t *session, const char *xpath,
int rc = SR_ERR_OK, op_rc = SR_ERR_OK;
SRP_LOG_INF("In %s", __FUNCTION__);
+
/* no-op for apply, we only care about SR_EV_ENABLED, SR_EV_VERIFY, SR_EV_ABORT */
- if (SR_EV_APPLY == event) {
+ if (SR_EV_APPLY == event)
return SR_ERR_OK;
- }
+
SRP_LOG_DBG("'%s' modified, event=%d", xpath, event);
/* get changes iterator */
rc = sr_get_changes_iter(session, xpath, &iter);
if (SR_ERR_OK != rc) {
+ sr_free_change_iter(iter);
SRP_LOG_ERR("Unable to retrieve change iterator: %s", sr_strerror(rc));
return rc;
}
- /* iterate over all changes */
- while ((SR_ERR_OK == op_rc || event == SR_EV_ABORT) &&
- (SR_ERR_OK == (rc = sr_get_change_next(session, iter, &op, &old_val, &new_val)))) {
+ foreach_change (session, iter, op, old_val, new_val) {
SRP_LOG_DBG("A change detected in '%s', op=%d", new_val ? new_val->xpath : old_val->xpath, op);
if_name = sr_xpath_key_value(new_val ? new_val->xpath : old_val->xpath, "interface", "name", &xpath_ctx);
@@ -102,23 +82,6 @@ ietf_interface_enable_disable_cb(sr_session_ctx_t *session, const char *xpath,
return op_rc;
}
-static int free_sw_interface_dump_ctx(dump_all_ctx * dctx)
-{
- if(dctx == NULL)
- return -1;
-
- if(dctx->intfcArray != NULL)
- {
- free(dctx->intfcArray);
- }
-
- dctx->intfcArray = NULL;
- dctx->capacity = 0;
- dctx->num_ifs = 0;
-
- return 0;
-}
-
/**
* @brief Modify existing IPv4/IPv6 config on an interface.
*/
@@ -169,7 +132,8 @@ interface_ipv46_config_modify(const char *if_name, sr_val_t *old_val,
}
/**
- * @brief Callback to be called by any config change in subtrees "/ietf-interfaces:interfaces/interface/ietf-ip:ipv4/address"
+ * @brief Callback to be called by any config change in subtrees
+ * "/ietf-interfaces:interfaces/interface/ietf-ip:ipv4/address"
* or "/ietf-interfaces:interfaces/interface/ietf-ip:ipv6/address".
*/
static int
@@ -178,6 +142,7 @@ ietf_interface_ipv46_address_change_cb(sr_session_ctx_t *session,
sr_notif_event_t event,
void *private_ctx)
{
+ UNUSED(private_ctx);
sr_change_iter_t *iter = NULL;
sr_change_oper_t op = SR_OP_CREATED;
sr_val_t *old_val = NULL;
@@ -207,13 +172,12 @@ ietf_interface_ipv46_address_change_cb(sr_session_ctx_t *session,
/* get changes iterator */
rc = sr_get_changes_iter(session, xpath, &iter);
if (SR_ERR_OK != rc) {
+ sr_free_change_iter(iter);
SRP_LOG_ERR("Unable to retrieve change iterator: %s", sr_strerror(rc));
return rc;
}
- /* iterate over all changes */
- while ((SR_ERR_OK == op_rc || event == SR_EV_ABORT) &&
- (SR_ERR_OK == (rc = sr_get_change_next(session, iter, &op, &old_val, &new_val)))) {
+ foreach_change(session, iter, op, old_val, new_val) {
SRP_LOG_DBG("A change detected in '%s', op=%d", new_val ? new_val->xpath : old_val->xpath, op);
if_name = strdup(sr_xpath_key_value(new_val ? new_val->xpath : old_val->xpath, "interface", "name", &xpath_ctx));
@@ -287,8 +251,9 @@ static int
ietf_interface_change_cb(sr_session_ctx_t *session, const char *xpath,
sr_notif_event_t event, void *private_ctx)
{
+ UNUSED(session); UNUSED(xpath); UNUSED(event); UNUSED(private_ctx);
+
SRP_LOG_INF("In %s", __FUNCTION__);
- SRP_LOG_DBG("'%s' modified, event=%d", xpath, event);
return SR_ERR_OK;
}
@@ -298,87 +263,80 @@ ietf_interface_change_cb(sr_session_ctx_t *session, const char *xpath,
*/
static int
ietf_interface_state_cb(const char *xpath, sr_val_t **values,
- size_t *values_cnt,
- __attribute__((unused)) uint64_t request_id,
- __attribute__((unused)) const char *original_xpath,
- __attribute__((unused)) void *private_ctx)
+ size_t *values_cnt, uint64_t request_id,
+ const char *original_xpath, void *private_ctx)
{
- sr_val_t *values_arr = NULL;
- int values_arr_size = 0, values_arr_cnt = 0;
- dump_all_ctx dctx;
- int nb_iface;
- vpp_interface_t* if_details;
- int rc = 0;
+ UNUSED(request_id); UNUSED(original_xpath); UNUSED(private_ctx);
+ struct elt* stack;
+ sw_interface_dump_t *dump;
+ sr_val_t *val = NULL;
+ int vc = 5; //number of answer per interfaces
+ int cnt = 0; //value counter
+ int rc = SR_ERR_OK;
SRP_LOG_INF("In %s", __FUNCTION__);
- if (! sr_xpath_node_name_eq(xpath, "interface")) {
- /* statistics, ipv4 and ipv6 state data not supported */
- *values = NULL;
- *values_cnt = 0;
- return SR_ERR_OK;
- }
+ if (!sr_xpath_node_name_eq(xpath, "interface"))
+ goto nothing_todo; //no interface field specified
/* dump interfaces */
- nb_iface = interface_dump_all(&dctx);
- if (nb_iface <= 0) {
- SRP_LOG_ERR_MSG("Error by processing of a interface dump request.");
- free_sw_interface_dump_ctx(&dctx);
- return SR_ERR_INTERNAL;
- }
+ stack = interface_dump_all();
+ if (!stack)
+ goto nothing_todo; //no element returned
/* allocate array of values to be returned */
- values_arr_size = nb_iface * 5;
- rc = sr_new_values(values_arr_size, &values_arr);
- if (0 != rc) {
- free_sw_interface_dump_ctx(&dctx);
- return rc;
- }
-
- int i = 0;
- for (; i < nb_iface; i++) {
- if_details = dctx.intfcArray+i;
-
- /* currently the only supported interface types are propVirtual / ethernetCsmacd */
- sr_val_build_xpath(&values_arr[values_arr_cnt], "%s[name='%s']/type", xpath, if_details->interface_name);
- sr_val_set_str_data(&values_arr[values_arr_cnt], SR_IDENTITYREF_T,
- strstr((char*)if_details->interface_name, "local0") ? "iana-if-type:propVirtual" : "iana-if-type:ethernetCsmacd");
- values_arr_cnt++;
-
- sr_val_build_xpath(&values_arr[values_arr_cnt], "%s[name='%s']/admin-status", xpath, if_details->interface_name);
- sr_val_set_str_data(&values_arr[values_arr_cnt], SR_ENUM_T, if_details->admin_up_down ? "up" : "down");
- values_arr_cnt++;
-
- sr_val_build_xpath(&values_arr[values_arr_cnt], "%s[name='%s']/oper-status", xpath, if_details->interface_name);
- sr_val_set_str_data(&values_arr[values_arr_cnt], SR_ENUM_T, if_details->link_up_down ? "up" : "down");
- values_arr_cnt++;
-
- if (if_details->l2_address_length > 0) {
- sr_val_build_xpath(&values_arr[values_arr_cnt], "%s[name='%s']/phys-address", xpath, if_details->interface_name);
- sr_val_build_str_data(&values_arr[values_arr_cnt], SR_STRING_T, "%02x:%02x:%02x:%02x:%02x:%02x",
- if_details->l2_address[0], if_details->l2_address[1], if_details->l2_address[2],
- if_details->l2_address[3], if_details->l2_address[4], if_details->l2_address[5]);
- values_arr_cnt++;
+ SRP_LOG_DBG("number of interfaces: %d", stack->id+1);
+ rc = sr_new_values((stack->id + 1)* vc, &val);
+ if (0 != rc)
+ goto nothing_todo;
+
+ foreach_stack_elt(stack) {
+ dump = (sw_interface_dump_t *) data;
+
+ SRP_LOG_DBG("State of interface %s", dump->interface_name);
+ //TODO need support for type propvirtual
+ sr_val_build_xpath(&val[cnt], "%s[name='%s']/type", xpath, dump->interface_name);
+ sr_val_set_str_data(&val[cnt], SR_IDENTITYREF_T, "iana-if-type:ethernetCsmacd");
+ cnt++;
+
+ //Be careful, it needs if-mib feature to work !
+ sr_val_build_xpath(&val[cnt], "%s[name='%s']/admin-status", xpath, dump->interface_name);
+ sr_val_set_str_data(&val[cnt], SR_ENUM_T, dump->link_up_down ? "up" : "down");
+ cnt++;
+
+ sr_val_build_xpath(&val[cnt], "%s[name='%s']/oper-status", xpath, dump->interface_name);
+ sr_val_set_str_data(&val[cnt], SR_ENUM_T, dump->link_up_down ? "up" : "down");
+ cnt++;
+
+ sr_val_build_xpath(&val[cnt], "%s[name='%s']/phys-address", xpath, dump->interface_name);
+ if (dump->l2_address_length > 0) {
+ sr_val_build_str_data(&val[cnt], SR_STRING_T,
+ "%02x:%02x:%02x:%02x:%02x:%02x",
+ dump->l2_address[0], dump->l2_address[1],
+ dump->l2_address[2], dump->l2_address[3],
+ dump->l2_address[4], dump->l2_address[5]);
} else {
- sr_val_build_xpath(&values_arr[values_arr_cnt], "%s[name='%s']/phys-address", xpath, if_details->interface_name);
- sr_val_build_str_data(&values_arr[values_arr_cnt], SR_STRING_T, "%02x:%02x:%02x:%02x:%02x:%02x", 0,0,0,0,0,0);
- values_arr_cnt++;
+ sr_val_build_str_data(&val[cnt], SR_STRING_T, "%02x:%02x:%02x:%02x:%02x:%02x", 0,0,0,0,0,0);
}
+ cnt++;
- sr_val_build_xpath(&values_arr[values_arr_cnt], "%s[name='%s']/speed", xpath, if_details->interface_name);
- values_arr[values_arr_cnt].type = SR_UINT64_T;
- values_arr[values_arr_cnt].data.uint64_val = if_details->link_speed;
- values_arr_cnt++;
- }
-
- SRP_LOG_DBG("Returning %zu state data elements for '%s'", values_arr, xpath);
+ sr_val_build_xpath(&val[cnt], "%s[name='%s']/speed", xpath, dump->interface_name);
+ val[cnt].type = SR_UINT64_T;
+ val[cnt].data.uint64_val = dump->link_speed;
+ cnt++;
- *values = values_arr;
- *values_cnt = values_arr_cnt;
+ free(dump);
+ }
- free_sw_interface_dump_ctx(&dctx);
+ *values = val;
+ *values_cnt = cnt;
return SR_ERR_OK;
+
+nothing_todo:
+ *values = NULL;
+ *values_cnt = 0;
+ return rc;
}
const xpath_t ietf_interfaces_xpaths[IETF_INTERFACES_SIZE] = {
diff --git a/src/plugins/ietf/ietf_interface.h b/src/plugins/ietf/ietf_interface.h
deleted file mode 100644
index 28a3783..0000000
--- a/src/plugins/ietf/ietf_interface.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (c) 2018 HUACHENTEL and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __IETF_INTERFACE_H__
-#define __IETF_INTERFACE_H__
-
-#include "../sc_model.h"
-
-#define IETF_INTERFACES_SIZE 5
-extern const xpath_t ietf_interfaces_xpaths[IETF_INTERFACES_SIZE];
-
-#endif /* __IETF_INTERFACE_H__ */
-
diff --git a/src/plugins/ietf/ietf_nat.c b/src/plugins/ietf/ietf_nat.c
index 86c8570..9b2890e 100644
--- a/src/plugins/ietf/ietf_nat.c
+++ b/src/plugins/ietf/ietf_nat.c
@@ -14,10 +14,11 @@
* limitations under the License.
*/
-#include "ietf_nat.h"
-#include "sc_vpp_comm.h"
-#include "sc_vpp_interface.h"
-#include "sc_vpp_nat.h"
+#include <scvpp/comm.h>
+#include <scvpp/interface.h>
+#include <scvpp/nat.h>
+
+#include "../sc_model.h"
#include <assert.h>
#include <string.h>
@@ -30,17 +31,6 @@
#include "../sys_util.h"
-static int ietf_nat_mod_cb(
- __attribute__((unused)) sr_session_ctx_t *session,
- __attribute__((unused)) const char *module_name,
- __attribute__((unused)) sr_notif_event_t event,
- __attribute__((unused)) void *private_ctx)
-{
- SRP_LOG_INF("Module subscribe: %s", module_name);
-
- return SR_ERR_OK;
-}
-
/**
* @brief Wrapper struct for VAPI address range payload.
*/
@@ -103,8 +93,7 @@ static int parse_instance_policy_external_ip_address_pool(
if (sr_xpath_node_name_eq(val->xpath, "pool-id")) {
SRP_LOG_WRN("%s not supported.", val->xpath);
} else if(sr_xpath_node_name_eq(val->xpath, "external-ip-pool")) {
- rc = get_address_from_prefix(tmp_str, val->data.string_val,
- VPP_IP4_ADDRESS_STRING_LEN, &prefix);
+ rc = prefix2address(tmp_str, val->data.string_val, &prefix);
if (0 != rc) {
SRP_LOG_ERR_MSG("Error translate");
return SR_ERR_INVAL_ARG;
@@ -136,8 +125,9 @@ static int parse_instance_policy_external_ip_address_pool(
// XPATH: /ietf-nat:nat/instances/instance[id='%s']/policy[id='%s']/external-ip-address-pool[pool-id='%s']/
static int instances_instance_policy_external_ip_address_pool_cb(
sr_session_ctx_t *ds, const char *xpath, sr_notif_event_t event,
- __attribute__((unused)) void *private_ctx)
+ void *private_ctx)
{
+ UNUSED(private_ctx);
sr_error_t rc = SR_ERR_OK;
sr_change_iter_t *it = NULL;
sr_change_oper_t oper;
@@ -150,6 +140,8 @@ static int instances_instance_policy_external_ip_address_pool_cb(
ARG_CHECK2(SR_ERR_INVAL_ARG, ds, xpath);
+ SRP_LOG_INF("In %s", __FUNCTION__);
+
new_address_r.payload.vrf_id = ~0;
old_address_r.payload.vrf_id = ~0;
@@ -165,8 +157,7 @@ static int instances_instance_policy_external_ip_address_pool_cb(
return SR_ERR_OK;
}
- while (sr_get_change_next(ds, it, &oper,
- &old_val, &new_val) == SR_ERR_OK) {
+ foreach_change (ds, it, oper, old_val, new_val) {
SRP_LOG_DBG("A change detected in '%s', op=%d",
new_val ? new_val->xpath : old_val->xpath, oper);
@@ -345,8 +336,7 @@ static int parse_instance_mapping_table_mapping_entry(
return SR_ERR_INVAL_ARG;
}
- rc = get_address_from_prefix(tmp_str, val->data.string_val,
- VPP_IP4_PREFIX_STRING_LEN, NULL);
+ rc = prefix2address(tmp_str, val->data.string_val, NULL);
if (0 != rc) {
SRP_LOG_ERR_MSG("Error translate");
return SR_ERR_INVAL_ARG;
@@ -367,8 +357,7 @@ static int parse_instance_mapping_table_mapping_entry(
return SR_ERR_INVAL_ARG;
}
- rc = get_address_from_prefix(tmp_str, val->data.string_val,
- VPP_IP4_ADDRESS_STRING_LEN, NULL);
+ rc = prefix2address(tmp_str, val->data.string_val, NULL);
if (0 != rc) {
SRP_LOG_ERR_MSG("Error translate");
return SR_ERR_INVAL_ARG;
@@ -402,8 +391,9 @@ static int parse_instance_mapping_table_mapping_entry(
// XPATH: /ietf-nat:nat/instances/instance[id='%s']/mapping-table/mapping-entry[index='%s']/
static int instances_instance_mapping_table_mapping_entry_cb(
sr_session_ctx_t *ds, const char *xpath, sr_notif_event_t event,
- __attribute__((unused)) void *private_ctx)
+ void *private_ctx)
{
+ UNUSED(private_ctx);
sr_error_t rc = SR_ERR_OK;
sr_change_iter_t *it = NULL;
sr_change_oper_t oper;
@@ -416,6 +406,8 @@ static int instances_instance_mapping_table_mapping_entry_cb(
ARG_CHECK2(SR_ERR_INVAL_ARG, ds, xpath);
+ SRP_LOG_INF("In %s", __FUNCTION__);
+
new_mapping.mtype = UNKNOWN;
old_mapping.mtype = UNKNOWN;
@@ -431,8 +423,7 @@ static int instances_instance_mapping_table_mapping_entry_cb(
return SR_ERR_OK;
}
- while (sr_get_change_next(ds, it, &oper,
- &old_val, &new_val) == SR_ERR_OK) {
+ foreach_change (ds, it, oper, old_val, new_val) {
SRP_LOG_DBG("A change detected in '%s', op=%d",
new_val ? new_val->xpath : old_val->xpath, oper);
@@ -503,15 +494,6 @@ error:
const xpath_t ietf_nat_xpaths[IETF_NAT_SIZE] = {
{
- .xpath = "ietf-nat",
- .method = MODULE,
- .datastore = SR_DS_RUNNING,
- .cb.mcb = ietf_nat_mod_cb,
- .private_ctx = NULL,
- .priority = 0,
- .opts = SR_SUBSCR_EV_ENABLED | SR_SUBSCR_APPLY_ONLY | SR_SUBSCR_CTX_REUSE
- },
- {
.xpath = "/ietf-nat:nat/instances/instance/policy/external-ip-address-pool",
.method = XPATH,
.datastore = SR_DS_RUNNING,
diff --git a/src/plugins/ietf/ietf_nat.h b/src/plugins/ietf/ietf_nat.h
deleted file mode 100644
index 7495209..0000000
--- a/src/plugins/ietf/ietf_nat.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (c) 2019 PANTHEON.tech.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __IETF_NAT_H__
-#define __IETF_NAT_H__
-
-#include "../sc_model.h"
-
-#define IETF_NAT_SIZE 3
-extern const xpath_t ietf_nat_xpaths[IETF_NAT_SIZE];
-
-#endif