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-12-15 20:03:50 -08:00
2008-12-15 23:43:36 -08:00
2008-11-25 17:59:27 -08:00
2008-11-16 19:19:38 -08:00
2008-10-31 00:17:34 -07:00
2008-07-16 20:20:11 -07:00
2008-11-03 02:48:48 -08:00
2008-11-25 17:59:27 -08:00
2008-11-03 00:25:16 -08:00
2008-11-03 00:25:16 -08:00
2008-01-28 15:02:46 -08:00
2008-07-05 19:01:28 -07:00
2008-11-03 00:23:42 -08:00
2008-10-31 00:53:57 -07:00
2008-11-25 17:35:18 -08:00
2008-11-03 00:26:09 -08:00
2008-12-14 23:13:08 -08:00
2008-11-23 17:22:55 -08:00
2008-07-25 21:43:18 -07:00
2008-11-24 00:09:29 -08:00
2008-11-19 15:44:53 -08:00
2008-11-20 20:39:09 -08:00
2008-11-03 00:23:42 -08:00
2008-10-28 13:24:06 -07:00
2008-11-03 18:21:05 -08:00
2008-11-23 17:26:26 -08:00
2008-11-18 23:38:23 -08:00
2008-10-10 10:16:34 -04:00
2008-11-24 16:07:50 -08:00
2008-11-20 01:54:27 -08:00
2008-11-25 17:30:50 -08:00
2008-10-31 00:53:57 -07:00
2008-11-23 17:26:26 -08:00
2008-12-16 01:15:11 -08:00
2008-10-07 08:38:24 +11:00
2008-10-07 08:38:24 +11:00
2008-11-28 02:19:15 -08:00
2008-11-25 21:17:14 -08:00
2008-06-11 21:00:38 -07:00
2008-11-24 15:52:46 -08:00
2008-11-25 17:35:18 -08:00
2008-10-01 07:46:49 -07:00
2008-11-03 18:21:05 -08:00
2008-02-28 22:14:32 -08:00
2008-10-16 15:24:51 -07:00
2008-11-02 00:28:10 -07:00
2008-11-19 15:43:27 -08:00
2008-01-28 14:55:41 -08:00
2008-11-12 01:41:09 -08:00
2008-10-07 15:58:17 -07:00
2008-01-28 14:55:41 -08:00
2008-12-05 22:43:26 -08:00
2008-12-15 23:43:36 -08:00
2008-01-28 14:55:41 -08:00
2008-11-03 00:24:34 -08:00
2008-12-05 22:56:07 -08:00
2008-10-31 00:53:57 -07:00
2008-01-28 14:55:41 -08:00
2008-11-25 21:17:14 -08:00
2008-12-09 00:13:04 -08:00
2007-07-31 02:27:57 -07:00
2008-05-01 02:47:38 -07:00
2007-07-31 02:27:57 -07:00
2008-11-03 00:24:34 -08:00
2008-12-15 23:43:36 -08:00
2008-06-05 04:02:33 +09:00
2008-10-29 01:41:45 -07:00
2008-11-25 13:55:15 -08:00
2008-10-29 02:11:14 -07:00
2008-01-28 15:00:10 -08:00
2008-08-06 02:39:30 -07:00
2007-10-10 16:55:54 -07:00
2008-06-17 16:38:23 -07:00
2008-03-24 14:51:51 -07:00
2008-11-25 17:56:49 -08:00
2008-11-25 01:05:54 -08:00
2008-01-31 19:27:24 -08:00