summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorPavel Kotucek <pavel.kotucek@pantheon.tech>2019-04-15 14:10:15 +0200
committerHongjun Ni <hongjun.ni@intel.com>2019-04-25 13:03:03 +0000
commit0d9d6a9a4446743cc9ac601a76b7e8594c3600ec (patch)
treef9bf38a492646ba9ded22e05207893c03bdfc8a4 /src/plugins
parentbda8bf51f84cc9fb7a2d875c1f35540e0b4a3db4 (diff)
ACL related changes
Added changes related to ACL implementation for sweetcomb: Change-Id: I5e734f77f0c149fb31fdff288fb46a4ece20a870 Signed-off-by: Pavel Kotucek <pavel.kotucek@pantheon.tech>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/ietf/ietf_nat.c6
-rw-r--r--src/plugins/sys_util.h40
2 files changed, 38 insertions, 8 deletions
diff --git a/src/plugins/ietf/ietf_nat.c b/src/plugins/ietf/ietf_nat.c
index 9b2890e..9613b52 100644
--- a/src/plugins/ietf/ietf_nat.c
+++ b/src/plugins/ietf/ietf_nat.c
@@ -93,7 +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 = prefix2address(tmp_str, val->data.string_val, &prefix);
+ rc = prefix2ip4(tmp_str, val->data.string_val, &prefix);
if (0 != rc) {
SRP_LOG_ERR_MSG("Error translate");
return SR_ERR_INVAL_ARG;
@@ -336,7 +336,7 @@ static int parse_instance_mapping_table_mapping_entry(
return SR_ERR_INVAL_ARG;
}
- rc = prefix2address(tmp_str, val->data.string_val, NULL);
+ rc = prefix2ip4(tmp_str, val->data.string_val, NULL);
if (0 != rc) {
SRP_LOG_ERR_MSG("Error translate");
return SR_ERR_INVAL_ARG;
@@ -357,7 +357,7 @@ static int parse_instance_mapping_table_mapping_entry(
return SR_ERR_INVAL_ARG;
}
- rc = prefix2address(tmp_str, val->data.string_val, NULL);
+ rc = prefix2ip4(tmp_str, val->data.string_val, NULL);
if (0 != rc) {
SRP_LOG_ERR_MSG("Error translate");
return SR_ERR_INVAL_ARG;
diff --git a/src/plugins/sys_util.h b/src/plugins/sys_util.h
index 692a012..3f85537 100644
--- a/src/plugins/sys_util.h
+++ b/src/plugins/sys_util.h
@@ -89,13 +89,12 @@ static inline int ip_prefix_split(const char* ip_prefix)
* @brief Get IPv4 host address from IPv4 prefix.
*
* @param[out] dst Host IPv4 address.
- * @param[in] src IPv4 Prefix.
- * @param[in] length dst buffer length.
+ * @param[in] src IPv4 prefix.
* @param[out] prefix Get Prefix length, optional value. Can be NULL.
* @return -1 when failure, 0 on success.
*/
static inline int
-prefix2address(char *dst, const char *src, uint8_t *prefix_length)
+prefix2ip4(char *dst, const char *src, uint8_t *prefix_length)
{
if (!src || !dst)
return -1;
@@ -104,10 +103,41 @@ prefix2address(char *dst, const char *src, uint8_t *prefix_length)
if (!p)
return -1; // '/' not found
- if ((p - src + 1) > VPP_IP4_ADDRESS_STRING_LEN) //+ 1 needed for \0
+ size_t size = p - src;
+ if ((size + 1) > VPP_IP4_ADDRESS_STRING_LEN) //+ 1 needed for \0
return -1;
- strncpy(dst, src, VPP_IP4_ADDRESS_STRING_LEN);
+ strncpy(dst, src, size);
+
+ if (!prefix_length)
+ *prefix_length = atoi(++p);
+
+ return 0;
+}
+
+/**
+ * @brief Get IPv6 host address from IPv6 prefix.
+ *
+ * @param[out] dst Host IPv6 address.
+ * @param[in] src IPv6 prefix.
+ * @param[out] prefix Get Prefix length, optional value. Can be NULL.
+ * @return -1 when failure, 0 on success.
+ */
+static inline int
+prefix2ip6(char *dst, const char *src, uint8_t *prefix_length)
+{
+ if (!src || !dst)
+ return -1;
+
+ char *p = strchr(src, '/');
+ if (!p)
+ return -1; // '/' not found
+
+ size_t size = p - src;
+ if ((size + 1) > VPP_IP6_ADDRESS_STRING_LEN) //+ 1 needed for \0
+ return -1;
+
+ strncpy(dst, src, size);
if (!prefix_length)
*prefix_length = atoi(++p);