Skip to content

Commit

Permalink
[INET]: Cleanup the xfrm4_tunnel_(un)register
Browse files Browse the repository at this point in the history
Both check for the family to select an appropriate tunnel list.
Consolidate this check and make the for() loop more readable.

Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Pavel Emelyanov authored and David S. Miller committed Nov 11, 2007
1 parent 99f9332 commit 358352b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions net/ipv4/tunnel4.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ static struct xfrm_tunnel *tunnel4_handlers;
static struct xfrm_tunnel *tunnel64_handlers;
static DEFINE_MUTEX(tunnel4_mutex);

static inline struct xfrm_tunnel **fam_handlers(unsigned short family)
{
return (family == AF_INET) ? &tunnel4_handlers : &tunnel64_handlers;
}

int xfrm4_tunnel_register(struct xfrm_tunnel *handler, unsigned short family)
{
struct xfrm_tunnel **pprev;
Expand All @@ -25,8 +30,7 @@ int xfrm4_tunnel_register(struct xfrm_tunnel *handler, unsigned short family)

mutex_lock(&tunnel4_mutex);

for (pprev = (family == AF_INET) ? &tunnel4_handlers : &tunnel64_handlers;
*pprev; pprev = &(*pprev)->next) {
for (pprev = fam_handlers(family); *pprev; pprev = &(*pprev)->next) {
if ((*pprev)->priority > priority)
break;
if ((*pprev)->priority == priority)
Expand All @@ -53,8 +57,7 @@ int xfrm4_tunnel_deregister(struct xfrm_tunnel *handler, unsigned short family)

mutex_lock(&tunnel4_mutex);

for (pprev = (family == AF_INET) ? &tunnel4_handlers : &tunnel64_handlers;
*pprev; pprev = &(*pprev)->next) {
for (pprev = fam_handlers(family); *pprev; pprev = &(*pprev)->next) {
if (*pprev == handler) {
*pprev = handler->next;
ret = 0;
Expand Down

0 comments on commit 358352b

Please sign in to comment.