Commit 33490170 authored by YOSHIFUJI Hideaki's avatar YOSHIFUJI Hideaki Committed by David S. Miller

[IPV4] SNMP: Move some statistic bits to net/ipv4/proc.c.

This also fixes memory leak in error path.
Signed-off-by: default avatarYOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 49ed67a9
...@@ -166,6 +166,9 @@ DECLARE_SNMP_STAT(struct linux_mib, net_statistics); ...@@ -166,6 +166,9 @@ DECLARE_SNMP_STAT(struct linux_mib, net_statistics);
#define NET_ADD_STATS_BH(field, adnd) SNMP_ADD_STATS_BH(net_statistics, field, adnd) #define NET_ADD_STATS_BH(field, adnd) SNMP_ADD_STATS_BH(net_statistics, field, adnd)
#define NET_ADD_STATS_USER(field, adnd) SNMP_ADD_STATS_USER(net_statistics, field, adnd) #define NET_ADD_STATS_USER(field, adnd) SNMP_ADD_STATS_USER(net_statistics, field, adnd)
extern int snmp_mib_init(void *ptr[2], size_t mibsize, size_t mibalign);
extern void snmp_mib_free(void *ptr[2]);
extern int sysctl_local_port_range[2]; extern int sysctl_local_port_range[2];
extern int sysctl_ip_default_ttl; extern int sysctl_ip_default_ttl;
extern int sysctl_ip_nonlocal_bind; extern int sysctl_ip_nonlocal_bind;
......
...@@ -1245,28 +1245,47 @@ static struct net_protocol icmp_protocol = { ...@@ -1245,28 +1245,47 @@ static struct net_protocol icmp_protocol = {
static int __init init_ipv4_mibs(void) static int __init init_ipv4_mibs(void)
{ {
net_statistics[0] = alloc_percpu(struct linux_mib); if (snmp_mib_init((void **)net_statistics,
net_statistics[1] = alloc_percpu(struct linux_mib); sizeof(struct linux_mib),
ip_statistics[0] = alloc_percpu(struct ipstats_mib); __alignof__(struct linux_mib)) < 0)
ip_statistics[1] = alloc_percpu(struct ipstats_mib); goto err_net_mib;
icmp_statistics[0] = alloc_percpu(struct icmp_mib); if (snmp_mib_init((void **)ip_statistics,
icmp_statistics[1] = alloc_percpu(struct icmp_mib); sizeof(struct ipstats_mib),
tcp_statistics[0] = alloc_percpu(struct tcp_mib); __alignof__(struct ipstats_mib)) < 0)
tcp_statistics[1] = alloc_percpu(struct tcp_mib); goto err_ip_mib;
udp_statistics[0] = alloc_percpu(struct udp_mib); if (snmp_mib_init((void **)icmp_statistics,
udp_statistics[1] = alloc_percpu(struct udp_mib); sizeof(struct icmp_mib),
udplite_statistics[0] = alloc_percpu(struct udp_mib); __alignof__(struct icmp_mib)) < 0)
udplite_statistics[1] = alloc_percpu(struct udp_mib); goto err_icmp_mib;
if (! if (snmp_mib_init((void **)tcp_statistics,
(net_statistics[0] && net_statistics[1] && ip_statistics[0] sizeof(struct tcp_mib),
&& ip_statistics[1] && tcp_statistics[0] && tcp_statistics[1] __alignof__(struct tcp_mib)) < 0)
&& udp_statistics[0] && udp_statistics[1] goto err_tcp_mib;
&& udplite_statistics[0] && udplite_statistics[1] ) ) if (snmp_mib_init((void **)udp_statistics,
return -ENOMEM; sizeof(struct udp_mib),
__alignof__(struct udp_mib)) < 0)
(void) tcp_mib_init(); goto err_udp_mib;
if (snmp_mib_init((void **)udplite_statistics,
sizeof(struct udp_mib),
__alignof__(struct udp_mib)) < 0)
goto err_udplite_mib;
tcp_mib_init();
return 0; return 0;
err_udplite_mib:
snmp_mib_free((void **)udp_statistics);
err_udp_mib:
snmp_mib_free((void **)tcp_statistics);
err_tcp_mib:
snmp_mib_free((void **)icmp_statistics);
err_icmp_mib:
snmp_mib_free((void **)ip_statistics);
err_ip_mib:
snmp_mib_free((void **)net_statistics);
err_net_mib:
return -ENOMEM;
} }
static int ipv4_proc_init(void); static int ipv4_proc_init(void);
......
...@@ -391,3 +391,28 @@ int __init ip_misc_proc_init(void) ...@@ -391,3 +391,28 @@ int __init ip_misc_proc_init(void)
goto out; goto out;
} }
int snmp_mib_init(void *ptr[2], size_t mibsize, size_t mibalign)
{
BUG_ON(ptr == NULL);
ptr[0] = __alloc_percpu(mibsize);
if (!ptr[0])
goto err0;
ptr[1] = __alloc_percpu(mibsize);
if (!ptr[1])
goto err1;
return 0;
err1:
free_percpu(ptr[0]);
ptr[0] = NULL;
err0:
return -ENOMEM;
}
void snmp_mib_free(void *ptr[2])
{
BUG_ON(ptr == NULL);
free_percpu(ptr[0]);
free_percpu(ptr[1]);
ptr[0] = ptr[1] = NULL;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment