Ilpo Järvinen
b1879204dd
ipmr: merge common code
Also removes redundant skb->len < x check which can't
be true once pskb_may_pull(skb, x) succeeded.
$ diff-funcs pim_rcv ipmr.c ipmr.c pim_rcv_v1
--- ipmr.c:pim_rcv()
+++ ipmr.c:pim_rcv_v1()
@@ -1,22 +1,27 @@
-static int pim_rcv(struct sk_buff * skb)
+int pim_rcv_v1(struct sk_buff * skb)
{
- struct pimreghdr *pim;
+ struct igmphdr *pim;
struct iphdr *encap;
struct net_device *reg_dev = NULL;
if (!pskb_may_pull(skb, sizeof(*pim) + sizeof(*encap)))
goto drop;
- pim = (struct pimreghdr *)skb_transport_header(skb);
- if (pim->type != ((PIM_VERSION<<4)|(PIM_REGISTER)) ||
- (pim->flags&PIM_NULL_REGISTER) ||
- (ip_compute_csum((void *)pim, sizeof(*pim)) != 0 &&
- csum_fold(skb_checksum(skb, 0, skb->len, 0))))
+ pim = igmp_hdr(skb);
+
+ if (!mroute_do_pim ||
+ skb->len < sizeof(*pim) + sizeof(*encap) ||
+ pim->group != PIM_V1_VERSION || pim->code != PIM_V1_REGISTER)
goto drop;
- /* check if the inner packet is destined to mcast group */
encap = (struct iphdr *)(skb_transport_header(skb) +
- sizeof(struct pimreghdr));
+ sizeof(struct igmphdr));
+ /*
+ Check that:
+ a. packet is really destinted to a multicast group
+ b. packet is not a NULL-REGISTER
+ c. packet is not truncated
+ */
if (!ipv4_is_multicast(encap->daddr) ||
encap->tot_len == 0 ||
ntohs(encap->tot_len) + sizeof(*pim) > skb->len)
@@ -40,9 +45,9 @@
skb->ip_summed = 0;
skb->pkt_type = PACKET_HOST;
dst_release(skb->dst);
+ skb->dst = NULL;
reg_dev->stats.rx_bytes += skb->len;
reg_dev->stats.rx_packets++;
- skb->dst = NULL;
nf_reset(skb);
netif_rx(skb);
dev_put(reg_dev);
$ codiff net/ipv4/ipmr.o.old net/ipv4/ipmr.o.new
net/ipv4/ipmr.c:
pim_rcv_v1 | -283
pim_rcv | -284
2 functions changed, 567 bytes removed
net/ipv4/ipmr.c:
__pim_rcv | +307
1 function changed, 307 bytes added
net/ipv4/ipmr.o.new:
3 functions changed, 307 bytes added, 567 bytes removed, diff: -260
(Tested on x86_64).
It seems that pimlen arg could be left out as well and
eq-sizedness of structs trapped with BUILD_BUG_ON but
I don't think that's more than a cosmetic flaw since there
aren't that many args anyway.
Compile tested.
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@helsinki.fi>
Signed-off-by: David S. Miller <davem@davemloft.net>
2008-12-16 01:15:11 -08:00
..
2008-11-21 17:15:03 -08:00
2008-11-20 20:32:15 -08:00
2008-11-19 22:42:41 -08:00
2008-11-12 23:39:10 -08:00
2008-12-08 01:14:16 -08:00
2008-12-14 23:17:26 -08:00
2008-12-14 23:18:00 -08:00
2008-11-28 02:19:15 -08:00
2008-12-14 23:16:58 -08:00
2008-12-15 23:44:31 -08:00
2008-12-15 01:06:23 -08:00
2008-12-08 01:19:06 -08:00
2008-12-10 15:18:31 -08:00
2008-12-10 15:18:31 -08:00
2008-07-19 22:34:43 -07:00
2008-11-23 23:24:32 -08:00
2008-12-16 01:15:11 -08:00
2008-12-15 20:03:50 -08:00
2008-11-03 18:21:05 -08:00
2008-12-14 23:18:30 -08:00
2008-09-30 03:03:35 -07:00
2008-11-25 17:59:00 -08:00
2008-01-28 14:56:52 -08:00
2008-11-21 17:15:03 -08:00
2008-12-12 14:45:27 -05:00
2008-12-15 20:03:50 -08:00
2008-12-15 20:03:50 -08:00
2008-11-28 03:05:19 -08:00
2008-11-03 18:21:05 -08:00
2008-11-24 00:09:29 -08:00
2008-12-15 20:03:50 -08:00
2008-12-12 14:45:25 -05:00
2008-11-26 23:48:40 -08:00
2008-12-10 15:18:31 -08:00
2008-12-15 20:03:50 -08:00
2008-11-27 15:30:53 -08:00
2008-12-15 20:03:50 -08:00
2008-11-07 23:37:50 -08:00
2008-12-02 19:50:27 -08:00
2008-11-20 04:26:21 -08:00
2008-12-12 14:01:35 -05:00
2008-11-03 18:21:05 -08:00
2008-12-14 23:16:22 -08:00
2008-11-19 18:49:57 -08:00
2008-11-21 11:08:18 -05:00
2008-11-25 01:02:08 -08:00
2008-11-20 16:44:00 -08:00
2008-07-27 09:45:34 -07:00