IPv4 RAW: Compact the API for the kernel
Subsystems (3)
PATCH 1/6 IPv4 RAW: Compact the API for the kernel
The raw sockets functions are explicitly used from inside the kernel in two places:
1. in ip_local_deliver_finish to intercept skb-s
2. in icmp_error
For this purposes many functions and even data structures, that are naturally internal for raw protocol, are exported.
Compact the API to two functions and hide all the other (including hash table and rwlock) inside the net/ipv4/raw.c
---
include/net/raw.h +3 -16
@@ -22,23 +22,10 @@extern struct proto raw_prot; -extern void raw_err (struct sock *,struct sk_buff *,u32 info); -extern int raw_rcv (struct sock *,struct sk_buff *); - -/* Note: v4 ICMP wants to get at this stuff, if you change the -* hashing mechanism, make sure you update icmp.c as well. -*/ -#define RAWV4_HTABLE_SIZE MAX_INET_PROTOS -extern struct hlist_head raw_v4_htable[RAWV4_HTABLE_SIZE ]; - -extern rwlock_t raw_v4_lock; +void raw_icmp_error (struct sk_buff *,int ,u32 ); +int raw_local_deliver (struct sk_buff *,int ); - -extern struct sock *__raw_v4_lookup (struct sock *sk,unsigned short num, -__be32 raddr,__be32 laddr, -int dif); - -extern int raw_v4_input (struct sk_buff *skb,struct iphdr *iph,int hash); +extern int raw_rcv (struct sock *,struct sk_buff *);#ifdef CONFIG_PROC_FS extern int raw_proc_init (void );
net/ipv4/icmp.c +1 -14
@@ -604,7 +604,6 @@ static void icmp_unreach(struct sk_buff *skb)struct icmphdr *icmph;int hash, protocol;struct net_protocol *ipprot; -struct sock *raw_sk;u32 info =0 ;/*
@@ -698,21 +697,9 @@ static void icmp_unreach(struct sk_buff *skb)/* * Deliver ICMP message to raw sockets. Pretty useless feature? */ +raw_icmp_error (skb, protocol, info); -/* Note: See raw.c and net/raw.h, RAWV4_HTABLE_SIZE==MAX_INET_PROTOS */ hash = protocol & (MAX_INET_PROTOS -1 ); -read_lock (&raw_v4_lock); -if ((raw_sk =sk_head (&raw_v4_htable[hash])) !=NULL ) { -while ((raw_sk =__raw_v4_lookup (raw_sk, protocol, iph->daddr, - iph->saddr, - skb->dev->ifindex)) !=NULL ) { -raw_err (raw_sk, skb, info); - raw_sk =sk_next (raw_sk); - iph = (struct iphdr *)skb->data; - } - } -read_unlock (&raw_v4_lock); -rcu_read_lock (); ipprot =rcu_dereference (inet_protos[hash]);if (ipprot && ipprot->err_handler)
net/ipv4/ip_input.c +4 -12
@@ -204,22 +204,14 @@ static int ip_local_deliver_finish(struct sk_buff *skb)rcu_read_lock (); { -/* Note: See raw.c and net/raw.h, RAWV4_HTABLE_SIZE==MAX_INET_PROTOS */ int protocol =ip_hdr (skb)->protocol; -int hash; -struct sock *raw_sk; +int hash, raw;struct net_protocol *ipprot; resubmit: - hash = protocol & (MAX_INET_PROTOS -1 ); - raw_sk =sk_head (&raw_v4_htable[hash]); - -/* If there maybe a raw socket we must check - if not we -* don't care less -*/ -if (raw_sk && !raw_v4_input (skb,ip_hdr (skb), hash)) - raw_sk =NULL ; + raw =raw_local_deliver (skb, protocol); + hash = protocol & (MAX_INET_PROTOS -1 );if ((ipprot =rcu_dereference (inet_protos[hash])) !=NULL ) {int ret;
@@ -237,7 +229,7 @@ static int ip_local_deliver_finish(struct sk_buff *skb) }IP_INC_STATS_BH (IPSTATS_MIB_INDELIVERS ); }else { -if (!raw_sk) { +if (!raw) {if (xfrm4_policy_check (NULL ,XFRM_POLICY_IN , skb)) {IP_INC_STATS_BH (IPSTATS_MIB_INUNKNOWNPROTOS ); icmp_send(skb, ICMP_DEST_UNREACH,
net/ipv4/raw.c +48 -5
83 lines not on this page · raw message
From: Pavel Emelyanov <[email protected]>
Date: Fri, 16 Nov 2007 17:05:59 +0300
Quoted 6 lines
The raw sockets functions are explicitly used from inside the kernel in two places:
1. in
ip_local_deliver_finishto intercept skb-s
2. inicmp_error
Quoted 7 lines
For this purposes many functions and even data structures, that are naturally internal for raw protocol, are exported.
Compact the API to two functions and hide all the other (including hash table and rwlock) inside the
net/ipv4/raw.cSigned-off-by Pavel Emelyanov <[email protected]>
Applied, thanks Pavel.