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

Commit 0bbf87d8 authored by Eric W. Biederman's avatar Eric W. Biederman Committed by David S. Miller
Browse files

net ipv4: Convert ipv4.ip_local_port_range to be per netns v3



- Move sysctl_local_ports from a global variable into struct netns_ipv4.
- Modify inet_get_local_port_range to take a struct net, and update all
  of the callers.
- Move the initialization of sysctl_local_ports into
   sysctl_net_ipv4.c:ipv4_sysctl_init_net from inet_connection_sock.c

v2:
- Ensure indentation used tabs
- Fixed ip.h so it applies cleanly to todays net-next

v3:
- Compile fixes of strange callers of inet_get_local_port_range.
  This patch now successfully passes an allmodconfig build.
  Removed manual inlining of inet_get_local_port_range in ipv4_local_port_range

Originally-by: default avatarSamya <samya@twitter.com>
Acked-by: default avatarNicolas Dichtel <nicolas.dichtel@6wind.com>
Signed-off-by: default avatar"Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 56d7b53f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2294,7 +2294,7 @@ static int cma_alloc_any_port(struct idr *ps, struct rdma_id_private *id_priv)
	int low, high, remaining;
	unsigned int rover;

	inet_get_local_port_range(&low, &high);
	inet_get_local_port_range(&init_net, &low, &high);
	remaining = (high - low) + 1;
	rover = net_random() % remaining + low;
retry:
+1 −1
Original line number Diff line number Diff line
@@ -2089,7 +2089,7 @@ static void vxlan_setup(struct net_device *dev)
	vxlan->age_timer.function = vxlan_cleanup;
	vxlan->age_timer.data = (unsigned long) vxlan;

	inet_get_local_port_range(&low, &high);
	inet_get_local_port_range(dev_net(dev), &low, &high);
	vxlan->port_min = low;
	vxlan->port_max = high;
	vxlan->dst_port = htons(vxlan_port);
+1 −5
Original line number Diff line number Diff line
@@ -217,11 +217,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
	}
}

extern struct local_ports {
	seqlock_t	lock;
	int		range[2];
} sysctl_local_ports;
void inet_get_local_port_range(int *low, int *high);
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)
+6 −0
Original line number Diff line number Diff line
@@ -15,6 +15,10 @@ struct fib_rules_ops;
struct hlist_head;
struct fib_table;
struct sock;
struct local_ports {
	seqlock_t	lock;
	int		range[2];
};

struct netns_ipv4 {
#ifdef CONFIG_SYSCTL
@@ -62,6 +66,8 @@ struct netns_ipv4 {
	int sysctl_icmp_ratemask;
	int sysctl_icmp_errors_use_inbound_ifaddr;

	struct local_ports sysctl_local_ports;

	int sysctl_tcp_ecn;

	kgid_t sysctl_ping_group_range[2];
+6 −14
Original line number Diff line number Diff line
@@ -29,27 +29,19 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
EXPORT_SYMBOL(inet_csk_timer_bug_msg);
#endif

/*
 * This struct holds the first and last local port number.
 */
struct local_ports sysctl_local_ports __read_mostly = {
	.lock = __SEQLOCK_UNLOCKED(sysctl_local_ports.lock),
	.range = { 32768, 61000 },
};

unsigned long *sysctl_local_reserved_ports;
EXPORT_SYMBOL(sysctl_local_reserved_ports);

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

	do {
		seq = read_seqbegin(&sysctl_local_ports.lock);
		seq = read_seqbegin(&net->ipv4.sysctl_local_ports.lock);

		*low = sysctl_local_ports.range[0];
		*high = sysctl_local_ports.range[1];
	} while (read_seqretry(&sysctl_local_ports.lock, seq));
		*low = net->ipv4.sysctl_local_ports.range[0];
		*high = net->ipv4.sysctl_local_ports.range[1];
	} while (read_seqretry(&net->ipv4.sysctl_local_ports.lock, seq));
}
EXPORT_SYMBOL(inet_get_local_port_range);

@@ -116,7 +108,7 @@ int inet_csk_get_port(struct sock *sk, unsigned short snum)
		int remaining, rover, low, high;

again:
		inet_get_local_port_range(&low, &high);
		inet_get_local_port_range(net, &low, &high);
		remaining = (high - low) + 1;
		smallest_rover = rover = net_random() % remaining + low;

Loading