Merge "[qca-nss-clients] Identifier rule support for IPv4 and IPv6."
diff --git a/netlink/nss_nlipsec.c b/netlink/nss_nlipsec.c
index cc8e669..6c836c4 100644
--- a/netlink/nss_nlipsec.c
+++ b/netlink/nss_nlipsec.c
@@ -43,6 +43,16 @@
 #include "nss_nlipv4_if.h"
 
 /*
+ * Function prototypes
+ */
+static int nss_nlipsec_op_create_tunnel(struct sk_buff *skb, struct genl_info *info);
+static int nss_nlipsec_op_destroy_tunnel(struct sk_buff *skb, struct genl_info *info);
+static int nss_nlipsec_op_add_sa(struct sk_buff *skb, struct genl_info *info);
+static int nss_nlipsec_op_delete_sa(struct sk_buff *skb, struct genl_info *info);
+static int nss_nlipsec_op_add_flow(struct sk_buff *skb, struct genl_info *info);
+static int nss_nlipsec_op_delete_flow(struct sk_buff *skb, struct genl_info *info);
+
+/*
  * Hold netdevice references
  */
 struct nss_nlipsec_ref {
@@ -72,10 +82,49 @@
 static struct nss_nlipsec_ctx gbl_ctx;
 
 /*
+ * Multicast group for sending message status & events
+ */
+static const struct genl_multicast_group nss_nlipsec_mcgrp[] = {
+	{.name = NSS_NLIPSEC_MCAST_GRP},
+};
+
+/*
+ * Operation table called by the generic netlink layer based on the command
+ */
+static struct genl_ops nss_nlipsec_ops[] = {
+	{ /* Create tunnel */
+		.cmd = NSS_NLIPSEC_CMD_ADD_TUNNEL,
+		.doit = nss_nlipsec_op_create_tunnel,
+	},
+	{ /* Destroy tunnel */
+		.cmd = NSS_NLIPSEC_CMD_DEL_TUNNEL,
+		.doit = nss_nlipsec_op_destroy_tunnel,
+	},
+	{ /* Add Security Association */
+		.cmd = NSS_NLIPSEC_CMD_ADD_SA,
+		.doit = nss_nlipsec_op_add_sa,
+	},
+	{ /* Delete Security Association */
+		.cmd = NSS_NLIPSEC_CMD_DEL_SA,
+		.doit = nss_nlipsec_op_delete_sa,
+	},
+	{ /* Add flow */
+		.cmd = NSS_NLIPSEC_CMD_ADD_FLOW,
+		.doit = nss_nlipsec_op_add_flow,
+	},
+	{ /* Delete flow */
+		.cmd = NSS_NLIPSEC_CMD_DEL_FLOW,
+		.doit = nss_nlipsec_op_delete_flow,
+	},
+};
+
+/*
  * IPsec family definition
  */
 static struct genl_family nss_nlipsec_family = {
+#if (LINUX_VERSION_CODE <= KERNEL_VERSION(4, 9, 0))
 	.id = GENL_ID_GENERATE,			/* Auto generate ID */
+#endif
 	.name = NSS_NLIPSEC_FAMILY,		/* Family name string */
 	.hdrsize = sizeof(struct nss_nlipsec_rule),/* NSS NETLINK IPsec rule */
 	.version = NSS_NL_VER,			/* Set it to NSS_NL version */
@@ -83,13 +132,10 @@
 	.netnsok = true,
 	.pre_doit = NULL,
 	.post_doit = NULL,
-};
-
-/*
- * Multicast group for sending message status & events
- */
-static const struct genl_multicast_group nss_nlipsec_mcgrp[] = {
-	{.name = NSS_NLIPSEC_MCAST_GRP},
+	.ops = nss_nlipsec_ops,
+	.n_ops = ARRAY_SIZE(nss_nlipsec_ops),
+	.mcgrps = nss_nlipsec_mcgrp,
+	.n_mcgrps = ARRAY_SIZE(nss_nlipsec_mcgrp)
 };
 
 /*
@@ -647,36 +693,6 @@
 }
 
 /*
- * Operation table called by the generic netlink layer based on the command
- */
-static struct genl_ops nss_nlipsec_ops[] = {
-	{ /* Create tunnel */
-		.cmd = NSS_NLIPSEC_CMD_ADD_TUNNEL,
-		.doit = nss_nlipsec_op_create_tunnel,
-	},
-	{ /* Destroy tunnel */
-		.cmd = NSS_NLIPSEC_CMD_DEL_TUNNEL,
-		.doit = nss_nlipsec_op_destroy_tunnel,
-	},
-	{ /* Add Security Association */
-		.cmd = NSS_NLIPSEC_CMD_ADD_SA,
-		.doit = nss_nlipsec_op_add_sa,
-	},
-	{ /* Delete Security Association */
-		.cmd = NSS_NLIPSEC_CMD_DEL_SA,
-		.doit = nss_nlipsec_op_delete_sa,
-	},
-	{ /* Add flow */
-		.cmd = NSS_NLIPSEC_CMD_ADD_FLOW,
-		.doit = nss_nlipsec_op_add_flow,
-	},
-	{ /* Delete flow */
-		.cmd = NSS_NLIPSEC_CMD_DEL_FLOW,
-		.doit = nss_nlipsec_op_delete_flow,
-	},
-};
-
-/*
  * nss_nlipsec_init()
  *	Netlink IPsec handler initialization
  */
@@ -700,7 +716,7 @@
 	/*
 	 * Register with the family
 	 */
-	error = genl_register_family_with_ops_groups(&nss_nlipsec_family, nss_nlipsec_ops, nss_nlipsec_mcgrp);
+	error = genl_register_family(&nss_nlipsec_family);
 	if (error != 0) {
 		nss_nl_info_always("Error: unable to register IPsec family\n");
 		return false;
diff --git a/netlink/nss_nlipv4.c b/netlink/nss_nlipv4.c
index 28d7022..084bab7 100644
--- a/netlink/nss_nlipv4.c
+++ b/netlink/nss_nlipv4.c
@@ -71,20 +71,6 @@
 static int nss_nlipv4_process_notify(struct notifier_block *nb, unsigned long val, void *data);
 
 /*
- * IPv4 family definition
- */
-static struct genl_family nss_nlipv4_family = {
-	.id = GENL_ID_GENERATE,				/* Auto generate ID */
-	.name = NSS_NLIPV4_FAMILY,			/* family name string */
-	.hdrsize = sizeof(struct nss_nlipv4_rule),	/* NSS NETLINK IPv4 rule */
-	.version = NSS_NL_VER,				/* Set it to NSS_NLIPv4 version */
-	.maxattr = NSS_IPV4_MAX_MSG_TYPES,		/* 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_nlipv4_mcgrp[] = {
@@ -100,6 +86,26 @@
 };
 
 /*
+ * IPv4 family definition
+ */
+static struct genl_family nss_nlipv4_family = {
+#if (LINUX_VERSION_CODE <= KERNEL_VERSION(4, 9, 0))
+	.id = GENL_ID_GENERATE,				/* Auto generate ID */
+#endif
+	.name = NSS_NLIPV4_FAMILY,			/* family name string */
+	.hdrsize = sizeof(struct nss_nlipv4_rule),	/* NSS NETLINK IPv4 rule */
+	.version = NSS_NL_VER,				/* Set it to NSS_NLIPv4 version */
+	.maxattr = NSS_IPV4_MAX_MSG_TYPES,		/* maximum commands supported */
+	.netnsok = true,
+	.pre_doit = NULL,
+	.post_doit = NULL,
+	.ops = nss_nlipv4_ops,
+	.n_ops = ARRAY_SIZE(nss_nlipv4_ops),
+	.mcgrps = nss_nlipv4_mcgrp,
+	.n_mcgrps = ARRAY_SIZE(nss_nlipv4_mcgrp)
+};
+
+/*
  * statistics call back handler for ipv4 from NSS
  */
 static struct notifier_block nss_ipv4_stats_notifier_nb = {
@@ -945,7 +951,7 @@
 	/*
 	 * register NETLINK ops with the family
 	 */
-	error = genl_register_family_with_ops_groups(&nss_nlipv4_family, nss_nlipv4_ops, nss_nlipv4_mcgrp);
+	error = genl_register_family(&nss_nlipv4_family);
 	if (error != 0) {
 		nss_nl_info_always("Error: unable to register IPv4 family\n");
 		return false;
diff --git a/netlink/nss_nlipv6.c b/netlink/nss_nlipv6.c
index febd39d..9021da6 100644
--- a/netlink/nss_nlipv6.c
+++ b/netlink/nss_nlipv6.c
@@ -79,20 +79,6 @@
 static int nss_nlipv6_process_notify(struct notifier_block *nb, unsigned long val, void *data);
 
 /*
- * IPV6 family definition
- */
-static struct genl_family nss_nlipv6_family = {
-	.id = GENL_ID_GENERATE,				/* Auto generate ID */
-	.name = NSS_NLIPV6_FAMILY,			/* family name string */
-	.hdrsize = sizeof(struct nss_nlipv6_rule),	/* NSS NETLINK IPV6 rule */
-	.version = NSS_NL_VER,				/* Set it to NSS_NLIPV6 version */
-	.maxattr = NSS_IPV6_MAX_MSG_TYPES,		/* maximum commands supported */
-	.netnsok = true,
-	.pre_doit = NULL,
-	.post_doit = NULL,
-};
-
-/*
  * multicast group for sending message status & events
  */
 static struct genl_multicast_group nss_nlipv6_mcgrp[] = {
@@ -108,6 +94,26 @@
 };
 
 /*
+ * IPV6 family definition
+ */
+static struct genl_family nss_nlipv6_family = {
+#if (LINUX_VERSION_CODE <= KERNEL_VERSION(4, 9, 0))
+	.id = GENL_ID_GENERATE,				/* Auto generate ID */
+#endif
+	.name = NSS_NLIPV6_FAMILY,			/* family name string */
+	.hdrsize = sizeof(struct nss_nlipv6_rule),	/* NSS NETLINK IPV6 rule */
+	.version = NSS_NL_VER,				/* Set it to NSS_NLIPV6 version */
+	.maxattr = NSS_IPV6_MAX_MSG_TYPES,		/* maximum commands supported */
+	.netnsok = true,
+	.pre_doit = NULL,
+	.post_doit = NULL,
+	.ops = nss_nlipv6_ops,
+	.n_ops = ARRAY_SIZE(nss_nlipv6_ops),
+	.mcgrps = nss_nlipv6_mcgrp,
+	.n_mcgrps = ARRAY_SIZE(nss_nlipv6_mcgrp)
+};
+
+/*
  * statistics call back handler for ipv6 from NSS
  */
 static struct notifier_block nss_ipv6_stats_notifier_nb = {
@@ -131,7 +137,11 @@
 
 	IPV6_ADDR_TO_IN6_ADDR(daddr, dst_addr);
 
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(4, 17, 0))
 	rt = rt6_lookup(&init_net, &daddr, NULL, 0, 0);
+#else
+	rt = rt6_lookup(&init_net, &daddr, NULL, 0, NULL, 0);
+#endif
 	if (!rt) {
 		return NULL;
 	}
@@ -946,7 +956,7 @@
 	/*
 	 * register NETLINK ops with the family
 	 */
-	error = genl_register_family_with_ops_groups(&nss_nlipv6_family, nss_nlipv6_ops, nss_nlipv6_mcgrp);
+	error = genl_register_family(&nss_nlipv6_family);
 	if (error != 0) {
 		nss_nl_info_always("Error: unable to register IPV6 family\n");
 		return false;