Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 122ff243 authored by WANG Cong's avatar WANG Cong Committed by David S. Miller
Browse files

ipv4: make ip_local_reserved_ports per netns



ip_local_port_range is already per netns, so should ip_local_reserved_ports
be. And since it is none by default we don't actually need it when we don't
enable CONFIG_SYSCTL.

By the way, rename inet_is_reserved_local_port() to inet_is_local_reserved_port()

Cc: "David S. Miller" <davem@davemloft.net>
Signed-off-by: default avatarCong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 9cc5e36d
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -208,11 +208,19 @@ static inline u64 snmp_fold_field64(void __percpu *mib, int offt, size_t syncp_o

void inet_get_local_port_range(struct net *net, int *low, int *high);

extern unsigned long *sysctl_local_reserved_ports;
static inline int inet_is_reserved_local_port(int port)
#if CONFIG_SYSCTL
static inline int inet_is_local_reserved_port(struct net *net, int port)
{
	return test_bit(port, sysctl_local_reserved_ports);
	if (!net->ipv4.sysctl_local_reserved_ports)
		return 0;
	return test_bit(port, net->ipv4.sysctl_local_reserved_ports);
}
#else
static inline int inet_is_local_reserved_port(struct net *net, int port)
{
	return 0;
}
#endif

extern int sysctl_ip_nonlocal_bind;

+4 −0
Original line number Diff line number Diff line
@@ -84,6 +84,10 @@ struct netns_ipv4 {

	atomic_t dev_addr_genid;

#ifdef CONFIG_SYSCTL
	unsigned long *sysctl_local_reserved_ports;
#endif

#ifdef CONFIG_IP_MROUTE
#ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
	struct mr_table		*mrt;
+2 −2
Original line number Diff line number Diff line
@@ -2501,11 +2501,11 @@ int proc_do_large_bitmap(struct ctl_table *table, int write,
	bool first = 1;
	size_t left = *lenp;
	unsigned long bitmap_len = table->maxlen;
	unsigned long *bitmap = (unsigned long *) table->data;
	unsigned long *bitmap = *(unsigned long **) table->data;
	unsigned long *tmp_bitmap = NULL;
	char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;

	if (!bitmap_len || !left || (*ppos && !write)) {
	if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
		*lenp = 0;
		return 0;
	}
+1 −7
Original line number Diff line number Diff line
@@ -1705,13 +1705,9 @@ static int __init inet_init(void)

	BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));

	sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
	if (!sysctl_local_reserved_ports)
		goto out;

	rc = proto_register(&tcp_prot, 1);
	if (rc)
		goto out_free_reserved_ports;
		goto out;

	rc = proto_register(&udp_prot, 1);
	if (rc)
@@ -1821,8 +1817,6 @@ static int __init inet_init(void)
	proto_unregister(&udp_prot);
out_unregister_tcp_proto:
	proto_unregister(&tcp_prot);
out_free_reserved_ports:
	kfree(sysctl_local_reserved_ports);
	goto out;
}

+1 −4
Original line number Diff line number Diff line
@@ -29,9 +29,6 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
EXPORT_SYMBOL(inet_csk_timer_bug_msg);
#endif

unsigned long *sysctl_local_reserved_ports;
EXPORT_SYMBOL(sysctl_local_reserved_ports);

void inet_get_local_port_range(struct net *net, int *low, int *high)
{
	unsigned int seq;
@@ -113,7 +110,7 @@ int inet_csk_get_port(struct sock *sk, unsigned short snum)

		smallest_size = -1;
		do {
			if (inet_is_reserved_local_port(rover))
			if (inet_is_local_reserved_port(net, rover))
				goto next_nolock;
			head = &hashinfo->bhash[inet_bhashfn(net, rover,
					hashinfo->bhash_size)];
Loading