[qca-nss-clients] Add IPv6 reasm netlink module
Support Multicast event notifications
Change-Id: Ice2b8aa66a1b5106e40f8b6ed9f5ad33cef4f080
Signed-off-by: Wayne Tan <wtan@codeaurora.org>
diff --git a/netlink/Makefile b/netlink/Makefile
index 2b6e1b0..9d85287 100644
--- a/netlink/Makefile
+++ b/netlink/Makefile
@@ -16,6 +16,7 @@
ccflags-y += -DCONFIG_NSS_NLC2C_TX=1
ccflags-y += -DCONFIG_NSS_NLC2C_RX=1
ccflags-y += -DCONFIG_NSS_NLIPV4_REASM=1
+ccflags-y += -DCONFIG_NSS_NLIPV6_REASM=1
qca-nss-netlink-objs := nss_nl.o
qca-nss-netlink-objs += nss_nlgre_redir_family.o
@@ -34,6 +35,7 @@
qca-nss-netlink-objs += nss_nlc2c_tx.o
qca-nss-netlink-objs += nss_nlc2c_rx.o
qca-nss-netlink-objs += nss_nlipv4_reasm.o
+qca-nss-netlink-objs += nss_nlipv6_reasm.o
CAPWAP_ENABLED:=CONFIG_PACKAGE_kmod-qca-nss-drv-capwapmgr=y
CAPWAP_CONFIG:=$(shell grep $(CAPWAP_ENABLED) $(TOPDIR)/.config)
diff --git a/netlink/include/nss_nlcmn_if.h b/netlink/include/nss_nlcmn_if.h
index b060670..836d582 100644
--- a/netlink/include/nss_nlcmn_if.h
+++ b/netlink/include/nss_nlcmn_if.h
@@ -49,6 +49,7 @@
NSS_NLCMN_SUBSYS_ETHRX,
NSS_NLCMN_SUBSYS_IPV4,
NSS_NLCMN_SUBSYS_IPV4_REASM,
+ NSS_NLCMN_SUBSYS_IPV6_REASM,
NSS_NLCMN_SUBSYS_N2H,
NSS_NLCMN_SUBSYS_MAX
};
diff --git a/netlink/include/nss_nlipv6_reasm_if.h b/netlink/include/nss_nlipv6_reasm_if.h
new file mode 100644
index 0000000..5a52d91
--- /dev/null
+++ b/netlink/include/nss_nlipv6_reasm_if.h
@@ -0,0 +1,32 @@
+/*
+ **************************************************************************
+ * Copyright (c) 2020, The Linux Foundation. All rights reserved.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for
+ * any purpose with or without fee is hereby granted, provided that the
+ * above copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ **************************************************************************
+ */
+
+/*
+ * @file nss_nlipv6_reasm_if.h
+ * NSS Netlink ipv6_reasm headers
+ */
+#ifndef __NSS_NLIPV6_REASM_IF_H
+#define __NSS_NLIPV6_REASM_IF_H
+
+/**
+ * ipv6_reasm forwarding Family
+ */
+#define NSS_NLIPV6_REASM_FAMILY "nss_ipv6_rsm"
+#define NSS_NLIPV6_REASM_MCAST_GRP "ipv6_rsm_mc"
+
+#endif /* __NSS_NLIPV6_REASM_IF_H */
diff --git a/netlink/nss_nl.c b/netlink/nss_nl.c
index ed98d21..75e75ee 100644
--- a/netlink/nss_nl.c
+++ b/netlink/nss_nl.c
@@ -64,6 +64,8 @@
#include "nss_nlc2c_rx_if.h"
#include "nss_nlipv4_reasm.h"
#include "nss_nlipv4_reasm_if.h"
+#include "nss_nlipv6_reasm.h"
+#include "nss_nlipv6_reasm_if.h"
#if defined (CONFIG_NSS_NLCRYPTO)
#include "nss_nlcrypto_if.h"
#else
@@ -236,6 +238,15 @@
.exit = NSS_NLIPV4_REASM_EXIT, /* exit */
.valid = CONFIG_NSS_NLIPV4_REASM /* 1 or 0 */
},
+ {
+ /*
+ * NSS_NLIPV6_REASM
+ */
+ .name = NSS_NLIPV6_REASM_FAMILY, /* ipv6_reasm */
+ .entry = NSS_NLIPV6_REASM_INIT, /* init */
+ .exit = NSS_NLIPV6_REASM_EXIT, /* exit */
+ .valid = CONFIG_NSS_NLIPV6_REASM /* 1 or 0 */
+ },
};
#define NSS_NL_FAMILY_HANDLER_SZ ARRAY_SIZE(family_handlers)
diff --git a/netlink/nss_nlipv6_reasm.c b/netlink/nss_nlipv6_reasm.c
new file mode 100644
index 0000000..49d9879
--- /dev/null
+++ b/netlink/nss_nlipv6_reasm.c
@@ -0,0 +1,172 @@
+/*
+ **************************************************************************
+ * Copyright (c) 2020, The Linux Foundation. All rights reserved.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for
+ * any purpose with or without fee is hereby granted, provided that the
+ * above copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ **************************************************************************
+ */
+
+/*
+ * nss_nlipv6_reasm.c
+ * NSS Netlink ipv6_reasm Handler
+ */
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/version.h>
+#include <linux/netlink.h>
+#include <linux/version.h>
+#include <linux/vmalloc.h>
+#include <linux/notifier.h>
+
+#include <net/genetlink.h>
+#include <net/sock.h>
+
+#include <nss_api_if.h>
+#include <nss_cmn.h>
+#include <nss_nl_if.h>
+#include "nss_nl.h"
+#include "nss_nlcmn_if.h"
+#include "nss_nlipv6_reasm_if.h"
+#include "nss_ipv6_reasm.h"
+
+/*
+ * prototypes
+ */
+static int nss_nlipv6_reasm_ops_get_stats(struct sk_buff *skb, struct genl_info *info);
+static int nss_nlipv6_reasm_process_notify(struct notifier_block *nb, unsigned long val, void *data);
+
+/*
+ * ipv6_reasm family definition
+ */
+static struct genl_family nss_nlipv6_reasm_family = {
+ .id = GENL_ID_GENERATE, /* Auto generate ID */
+ .name = NSS_NLIPV6_REASM_FAMILY, /* family name string */
+ .hdrsize = sizeof(struct nss_ipv6_reasm_stats_notification), /* NSS NETLINK ipv6_reasm stats */
+ .version = NSS_NL_VER, /* Set it to NSS_NLIPV6_REASM version */
+ .maxattr = NSS_STATS_EVENT_MAX, /* maximum commands supported */
+ .netnsok = true,
+ .pre_doit = NULL,
+ .post_doit = NULL,
+};
+
+/*
+ * multicast group for sending message status & events
+ */
+static const struct genl_multicast_group nss_nlipv6_reasm_mcgrp[] = {
+ {.name = NSS_NLIPV6_REASM_MCAST_GRP},
+};
+
+/*
+ * operation table called by the generic netlink layer based on the command
+ */
+static struct genl_ops nss_nlipv6_reasm_ops[] = {
+ {.cmd = NSS_STATS_EVENT_NOTIFY, .doit = nss_nlipv6_reasm_ops_get_stats},
+};
+
+/*
+ * stats call back handler for ipv6_reasm from NSS
+ */
+static struct notifier_block nss_ipv6_reasm_stats_notifier_nb = {
+ .notifier_call = nss_nlipv6_reasm_process_notify,
+};
+
+/*
+ * nss_nlipv6_reasm_ops_get_stats()
+ * get stats handler
+ */
+static int nss_nlipv6_reasm_ops_get_stats(struct sk_buff *skb, struct genl_info *info)
+{
+ return 0;
+}
+
+/*
+ * nss_nlipv6_reasm_process_notify()
+ * process notification messages from NSS
+ */
+static int nss_nlipv6_reasm_process_notify(struct notifier_block *nb, unsigned long val, void *data)
+{
+ struct sk_buff *skb;
+ struct nss_ipv6_reasm_stats_notification *nss_stats, *nl_stats;
+
+ skb = nss_nl_new_msg(&nss_nlipv6_reasm_family, NSS_NLCMN_SUBSYS_IPV6_REASM);
+ if (!skb) {
+ nss_nl_error("unable to allocate NSS_NLIPV6_REASM event\n");
+ return NOTIFY_DONE;
+ }
+
+ nl_stats = nss_nl_get_data(skb);
+ nss_stats = (struct nss_ipv6_reasm_stats_notification *)data;
+ memcpy(nl_stats, nss_stats, sizeof(struct nss_ipv6_reasm_stats_notification));
+ nss_nl_mcast_event(&nss_nlipv6_reasm_family, skb);
+
+ return NOTIFY_DONE;
+}
+
+/*
+ * nss_nlipv6_reasm_init()
+ * handler init
+ */
+bool nss_nlipv6_reasm_init(void)
+{
+ int error,ret;
+
+ nss_nl_info_always("Init NSS netlink ipv6_reasm handler\n");
+
+ /*
+ * register NETLINK ops with the family
+ */
+ error = genl_register_family_with_ops_groups(&nss_nlipv6_reasm_family, nss_nlipv6_reasm_ops, nss_nlipv6_reasm_mcgrp);
+ if (error) {
+ nss_nl_info_always("Error: unable to register ipv6_reasm family\n");
+ return false;
+ }
+
+ /*
+ * register device call back handler for ipv6_reasm from NSS
+ */
+ ret = nss_ipv6_reasm_stats_register_notifier(&nss_ipv6_reasm_stats_notifier_nb);
+ if (ret) {
+ nss_nl_info_always("Error: retreiving the NSS Context\n");
+ genl_unregister_family(&nss_nlipv6_reasm_family);
+ return false;
+ }
+
+ return true;
+}
+
+/*
+ * nss_nlipv6_reasm_exit()
+ * handler exit
+ */
+bool nss_nlipv6_reasm_exit(void)
+{
+ int error;
+
+ nss_nl_info_always("Exit NSS netlink ipv6_reasm handler\n");
+
+ /*
+ * Unregister the device callback handler for ipv6_reasm
+ */
+ nss_ipv6_reasm_stats_unregister_notifier(&nss_ipv6_reasm_stats_notifier_nb);
+
+ /*
+ * unregister the ops family
+ */
+ error = genl_unregister_family(&nss_nlipv6_reasm_family);
+ if (error) {
+ nss_nl_info_always("unable to unregister ipv6_reasm NETLINK family\n");
+ return false;
+ }
+
+ return true;
+}
diff --git a/netlink/nss_nlipv6_reasm.h b/netlink/nss_nlipv6_reasm.h
new file mode 100644
index 0000000..2337078
--- /dev/null
+++ b/netlink/nss_nlipv6_reasm.h
@@ -0,0 +1,37 @@
+/*
+ **************************************************************************
+ * Copyright (c) 2020, The Linux Foundation. All rights reserved.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for
+ * any purpose with or without fee is hereby granted, provided that the
+ * above copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ **************************************************************************
+ */
+
+/*
+ * nss_nlipv6_reasm.h
+ * NSS Netlink ipv6_reasm API definitions
+ */
+#ifndef __NSS_NLIPV6_REASM_H
+#define __NSS_NLIPV6_REASM_H
+
+bool nss_nlipv6_reasm_init(void);
+bool nss_nlipv6_reasm_exit(void);
+
+#if defined(CONFIG_NSS_NLIPV6_REASM)
+#define NSS_NLIPV6_REASM_INIT nss_nlipv6_reasm_init
+#define NSS_NLIPV6_REASM_EXIT nss_nlipv6_reasm_exit
+#else
+#define NSS_NLIPV6_REASM_INIT 0
+#define NSS_NLIPV6_REASM_EXIT 0
+#endif /* !CONFIG_NSS_NLIPV6_REASM */
+
+#endif /* __NSS_NLIPV6_REASM_H */