Commit 1c106eb0 authored by Joel Granados's avatar Joel Granados Committed by David S. Miller
Browse files

net: ipv{6,4}: Remove the now superfluous sentinel elements from ctl_table array

This commit comes at the tail end of a greater effort to remove the
empty elements at the end of the ctl_table arrays (sentinels) which
will reduce the overall build time size of the kernel and run time
memory bloat by ~64 bytes per sentinel (further information Link :
https://lore.kernel.org/all/ZO5Yx5JFogGi%2FcBo@bombadil.infradead.org/

)

* Remove sentinel element from ctl_table structs.
* Remove the zeroing out of an array element (to make it look like a
  sentinel) in sysctl_route_net_init And ipv6_route_sysctl_init.
  This is not longer needed and is safe after commit c899710f
  ("networking: Update to register_net_sysctl_sz") added the array size
  to the ctl_table registration.
* Remove extra sentinel element in the declaration of devinet_vars.
* Removed the "-1" in __devinet_sysctl_register, sysctl_route_net_init,
  ipv6_sysctl_net_init and ipv4_sysctl_init_net that adjusted for having
  an extra empty element when looping over ctl_table arrays
* Replace the for loop stop condition in __addrconf_sysctl_register that
  tests for procname == NULL with one that depends on array size
* Removing the unprivileged user check in ipv6_route_sysctl_init is
  safe as it is replaced by calling ipv6_route_sysctl_table_size;
  introduced in commit c899710f ("networking: Update to
  register_net_sysctl_sz")
* Use a table_size variable to keep the value of ARRAY_SIZE

Signed-off-by: default avatarJoel Granados <j.granados@samsung.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ce218712
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -2520,7 +2520,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,

static struct devinet_sysctl_table {
	struct ctl_table_header *sysctl_header;
	struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
	struct ctl_table devinet_vars[IPV4_DEVCONF_MAX];
} devinet_sysctl = {
	.devinet_vars = {
		DEVINET_SYSCTL_COMPLEX_ENTRY(FORWARDING, "forwarding",
@@ -2583,7 +2583,7 @@ static int __devinet_sysctl_register(struct net *net, char *dev_name,
	if (!t)
		goto out;

	for (i = 0; i < ARRAY_SIZE(t->devinet_vars) - 1; i++) {
	for (i = 0; i < ARRAY_SIZE(t->devinet_vars); i++) {
		t->devinet_vars[i].data += (char *)p - (char *)&ipv4_devconf;
		t->devinet_vars[i].extra1 = p;
		t->devinet_vars[i].extra2 = net;
@@ -2657,7 +2657,6 @@ static struct ctl_table ctl_forward_entry[] = {
		.extra1		= &ipv4_devconf,
		.extra2		= &init_net,
	},
	{ },
};
#endif

+0 −2
Original line number Diff line number Diff line
@@ -580,7 +580,6 @@ static struct ctl_table ip4_frags_ns_ctl_table[] = {
		.proc_handler	= proc_dointvec_minmax,
		.extra1		= &dist_min,
	},
	{ }
};

/* secret interval has been deprecated */
@@ -593,7 +592,6 @@ static struct ctl_table ip4_frags_ctl_table[] = {
		.mode		= 0644,
		.proc_handler	= proc_dointvec_jiffies,
	},
	{ }
};

static int __net_init ip4_frags_ns_ctl_register(struct net *net)
+2 −6
Original line number Diff line number Diff line
@@ -3496,7 +3496,6 @@ static struct ctl_table ipv4_route_table[] = {
		.mode		= 0644,
		.proc_handler	= proc_dointvec,
	},
	{ }
};

static const char ipv4_route_flush_procname[] = "flush";
@@ -3530,7 +3529,6 @@ static struct ctl_table ipv4_route_netns_table[] = {
		.mode       = 0644,
		.proc_handler   = proc_dointvec,
	},
	{ },
};

static __net_init int sysctl_route_net_init(struct net *net)
@@ -3548,16 +3546,14 @@ static __net_init int sysctl_route_net_init(struct net *net)

		/* Don't export non-whitelisted sysctls to unprivileged users */
		if (net->user_ns != &init_user_ns) {
			if (tbl[0].procname != ipv4_route_flush_procname) {
				tbl[0].procname = NULL;
			if (tbl[0].procname != ipv4_route_flush_procname)
				table_size = 0;
		}
		}

		/* Update the variables to point into the current struct net
		 * except for the first element flush
		 */
		for (i = 1; i < ARRAY_SIZE(ipv4_route_netns_table) - 1; i++)
		for (i = 1; i < table_size; i++)
			tbl[i].data += (void *)net - (void *)&init_net;
	}
	tbl[0].extra1 = net;
+3 −4
Original line number Diff line number Diff line
@@ -575,7 +575,6 @@ static struct ctl_table ipv4_table[] = {
		.extra1		= &sysctl_fib_sync_mem_min,
		.extra2		= &sysctl_fib_sync_mem_max,
	},
	{ }
};

static struct ctl_table ipv4_net_table[] = {
@@ -1502,11 +1501,11 @@ static struct ctl_table ipv4_net_table[] = {
		.proc_handler	= proc_dou8vec_minmax,
		.extra1		= SYSCTL_ONE,
	},
	{ }
};

static __net_init int ipv4_sysctl_init_net(struct net *net)
{
	size_t table_size = ARRAY_SIZE(ipv4_net_table);
	struct ctl_table *table;

	table = ipv4_net_table;
@@ -1517,7 +1516,7 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
		if (!table)
			goto err_alloc;

		for (i = 0; i < ARRAY_SIZE(ipv4_net_table) - 1; i++) {
		for (i = 0; i < table_size; i++) {
			if (table[i].data) {
				/* Update the variables to point into
				 * the current struct net
@@ -1533,7 +1532,7 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
	}

	net->ipv4.ipv4_hdr = register_net_sysctl_sz(net, "net/ipv4", table,
						    ARRAY_SIZE(ipv4_net_table));
						    table_size);
	if (!net->ipv4.ipv4_hdr)
		goto err_reg;

+0 −1
Original line number Diff line number Diff line
@@ -152,7 +152,6 @@ static struct ctl_table xfrm4_policy_table[] = {
		.mode           = 0644,
		.proc_handler   = proc_dointvec,
	},
	{ }
};

static __net_init int xfrm4_net_sysctl_init(struct net *net)
Loading