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

Commit 7eb95156 authored by Pavel Emelyanov's avatar Pavel Emelyanov Committed by David S. Miller
Browse files

[INET]: Collect frag queues management objects together



There are some objects that are common in all the places
which are used to keep track of frag queues, they are:

 * hash table
 * LRU list
 * rw lock
 * rnd number for hash function
 * the number of queues
 * the amount of memory occupied by queues
 * secret timer

Move all this stuff into one structure (struct inet_frags)
to make it possible use them uniformly in the future. Like
with the previous patch this mostly consists of hunks like

-    write_lock(&ipfrag_lock);
+    write_lock(&ip4_frags.lock);

To address the issue with exporting the number of queues and
the amount of memory occupied by queues outside the .c file
they are declared in, I introduce a couple of helpers.

Signed-off-by: default avatarPavel Emelyanov <xemul@openvz.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 5ab11c98
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -18,4 +18,19 @@ struct inet_frag_queue {
#define LAST_IN			1
};

#define INETFRAGS_HASHSZ		64

struct inet_frags {
	struct list_head	lru_list;
	struct hlist_head	hash[INETFRAGS_HASHSZ];
	rwlock_t		lock;
	u32			rnd;
	int			nqueues;
	atomic_t		mem;
	struct timer_list	secret_timer;
};

void inet_frags_init(struct inet_frags *);
void inet_frags_fini(struct inet_frags *);

#endif
+2 −2
Original line number Diff line number Diff line
@@ -333,8 +333,8 @@ enum ip_defrag_users
};

int ip_defrag(struct sk_buff *skb, u32 user);
extern int ip_frag_nqueues;
extern atomic_t ip_frag_mem;
int ip_frag_mem(void);
int ip_frag_nqueues(void);

/*
 *	Functions provided by ip_forward.c
+2 −2
Original line number Diff line number Diff line
@@ -252,8 +252,8 @@ struct ipv6_txoptions *ipv6_fixup_options(struct ipv6_txoptions *opt_space,

extern int ipv6_opt_accepted(struct sock *sk, struct sk_buff *skb);

extern int ip6_frag_nqueues;
extern atomic_t ip6_frag_mem;
int ip6_frag_nqueues(void);
int ip6_frag_mem(void);

#define IPV6_FRAG_TIMEOUT	(60*HZ)		/* 60 seconds */

+2 −1
Original line number Diff line number Diff line
@@ -10,7 +10,8 @@ obj-y := route.o inetpeer.o protocol.o \
	     tcp_minisocks.o tcp_cong.o \
	     datagram.o raw.o udp.o udplite.o \
	     arp.o icmp.o devinet.o af_inet.o  igmp.o \
	     sysctl_net_ipv4.o fib_frontend.o fib_semantics.o
	     sysctl_net_ipv4.o fib_frontend.o fib_semantics.o \
	     inet_fragment.o

obj-$(CONFIG_IP_FIB_HASH) += fib_hash.o
obj-$(CONFIG_IP_FIB_TRIE) += fib_trie.o
+44 −0
Original line number Diff line number Diff line
/*
 * inet fragments management
 *
 *		This program is free software; you can redistribute it and/or
 *		modify it under the terms of the GNU General Public License
 *		as published by the Free Software Foundation; either version
 *		2 of the License, or (at your option) any later version.
 *
 * 		Authors:	Pavel Emelyanov <xemul@openvz.org>
 *				Started as consolidation of ipv4/ip_fragment.c,
 *				ipv6/reassembly. and ipv6 nf conntrack reassembly
 */

#include <linux/list.h>
#include <linux/spinlock.h>
#include <linux/module.h>
#include <linux/timer.h>
#include <linux/mm.h>

#include <net/inet_frag.h>

void inet_frags_init(struct inet_frags *f)
{
	int i;

	for (i = 0; i < INETFRAGS_HASHSZ; i++)
		INIT_HLIST_HEAD(&f->hash[i]);

	INIT_LIST_HEAD(&f->lru_list);
	rwlock_init(&f->lock);

	f->rnd = (u32) ((num_physpages ^ (num_physpages>>7)) ^
				   (jiffies ^ (jiffies >> 6)));

	f->nqueues = 0;
	atomic_set(&f->mem, 0);

}
EXPORT_SYMBOL(inet_frags_init);

void inet_frags_fini(struct inet_frags *f)
{
}
EXPORT_SYMBOL(inet_frags_fini);
Loading