Release 4.11 net/ipv4/ipcomp.c
/*
* IP Payload Compression Protocol (IPComp) - RFC3173.
*
* Copyright (c) 2003 James Morris <jmorris@intercode.com.au>
*
* 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.
*
* Todo:
* - Tunable compression parameters.
* - Compression stats.
* - Adaptive compression.
*/
#include <linux/module.h>
#include <linux/err.h>
#include <linux/rtnetlink.h>
#include <net/ip.h>
#include <net/xfrm.h>
#include <net/icmp.h>
#include <net/ipcomp.h>
#include <net/protocol.h>
#include <net/sock.h>
static int ipcomp4_err(struct sk_buff *skb, u32 info)
{
struct net *net = dev_net(skb->dev);
__be32 spi;
const struct iphdr *iph = (const struct iphdr *)skb->data;
struct ip_comp_hdr *ipch = (struct ip_comp_hdr *)(skb->data+(iph->ihl<<2));
struct xfrm_state *x;
switch (icmp_hdr(skb)->type) {
case ICMP_DEST_UNREACH:
if (icmp_hdr(skb)->code != ICMP_FRAG_NEEDED)
return 0;
case ICMP_REDIRECT:
break;
default:
return 0;
}
spi = htonl(ntohs(ipch->cpi));
x = xfrm_state_lookup(net, skb->mark, (const xfrm_address_t *)&iph->daddr,
spi, IPPROTO_COMP, AF_INET);
if (!x)
return 0;
if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH)
ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
else
ipv4_redirect(skb, net, 0, 0, IPPROTO_COMP, 0);
xfrm_state_put(x);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Herbert Xu | 76 | 36.36% | 1 | 10.00% |
David S. Miller | 55 | 26.32% | 2 | 20.00% |
James Morris | 36 | 17.22% | 1 | 10.00% |
Alexey Dobriyan | 14 | 6.70% | 2 | 20.00% |
Steffen Klassert | 13 | 6.22% | 1 | 10.00% |
Arnaldo Carvalho de Melo | 8 | 3.83% | 1 | 10.00% |
Jamal Hadi Salim | 4 | 1.91% | 1 | 10.00% |
Eric Dumazet | 3 | 1.44% | 1 | 10.00% |
Total | 209 | 100.00% | 10 | 100.00% |
/* We always hold one tunnel user reference to indicate a tunnel */
static struct xfrm_state *ipcomp_tunnel_create(struct xfrm_state *x)
{
struct net *net = xs_net(x);
struct xfrm_state *t;
t = xfrm_state_alloc(net);
if (!t)
goto out;
t->id.proto = IPPROTO_IPIP;
t->id.spi = x->props.saddr.a4;
t->id.daddr.a4 = x->id.daddr.a4;
memcpy(&t->sel, &x->sel, sizeof(t->sel));
t->props.family = AF_INET;
t->props.mode = x->props.mode;
t->props.saddr.a4 = x->props.saddr.a4;
t->props.flags = x->props.flags;
t->props.extra_flags = x->props.extra_flags;
memcpy(&t->mark, &x->mark, sizeof(t->mark));
if (xfrm_init_state(t))
goto error;
atomic_set(&t->tunnel_users, 1);
out:
return t;
error:
t->km.state = XFRM_STATE_DEAD;
xfrm_state_put(t);
t = NULL;
goto out;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Herbert Xu | 141 | 61.84% | 7 | 50.00% |
James Morris | 40 | 17.54% | 1 | 7.14% |
Jamal Hadi Salim | 20 | 8.77% | 1 | 7.14% |
Alexey Dobriyan | 13 | 5.70% | 2 | 14.29% |
Nicolas Dichtel | 12 | 5.26% | 1 | 7.14% |
Ian Morris | 1 | 0.44% | 1 | 7.14% |
Mitsuru Kanda | 1 | 0.44% | 1 | 7.14% |
Total | 228 | 100.00% | 14 | 100.00% |
/*
* Must be protected by xfrm_cfg_mutex. State and tunnel user references are
* always incremented on success.
*/
static int ipcomp_tunnel_attach(struct xfrm_state *x)
{
struct net *net = xs_net(x);
int err = 0;
struct xfrm_state *t;
u32 mark = x->mark.v & x->mark.m;
t = xfrm_state_lookup(net, mark, (xfrm_address_t *)&x->id.daddr.a4,
x->props.saddr.a4, IPPROTO_IPIP, AF_INET);
if (!t) {
t = ipcomp_tunnel_create(x);
if (!t) {
err = -EINVAL;
goto out;
}
xfrm_state_insert(t);
xfrm_state_hold(t);
}
x->tunnel = t;
atomic_inc(&t->tunnel_users);
out:
return err;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Herbert Xu | 109 | 78.99% | 2 | 40.00% |
Jamal Hadi Salim | 17 | 12.32% | 1 | 20.00% |
Alexey Dobriyan | 12 | 8.70% | 2 | 40.00% |
Total | 138 | 100.00% | 5 | 100.00% |
static int ipcomp4_init_state(struct xfrm_state *x)
{
int err = -EINVAL;
x->props.header_len = 0;
switch (x->props.mode) {
case XFRM_MODE_TRANSPORT:
break;
case XFRM_MODE_TUNNEL:
x->props.header_len += sizeof(struct iphdr);
break;
default:
goto out;
}
err = ipcomp_init_state(x);
if (err)
goto out;
if (x->props.mode == XFRM_MODE_TUNNEL) {
err = ipcomp_tunnel_attach(x);
if (err)
goto out;
}
err = 0;
out:
return err;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
James Morris | 69 | 63.89% | 2 | 22.22% |
Herbert Xu | 34 | 31.48% | 5 | 55.56% |
David S. Miller | 3 | 2.78% | 1 | 11.11% |
Masahide Nakamura | 2 | 1.85% | 1 | 11.11% |
Total | 108 | 100.00% | 9 | 100.00% |
static int ipcomp4_rcv_cb(struct sk_buff *skb, int err)
{
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Steffen Klassert | 17 | 100.00% | 1 | 100.00% |
Total | 17 | 100.00% | 1 | 100.00% |
static const struct xfrm_type ipcomp_type = {
.description = "IPCOMP4",
.owner = THIS_MODULE,
.proto = IPPROTO_COMP,
.init_state = ipcomp4_init_state,
.destructor = ipcomp_destroy,
.input = ipcomp_input,
.output = ipcomp_output
};
static struct xfrm4_protocol ipcomp4_protocol = {
.handler = xfrm4_rcv,
.input_handler = xfrm_input,
.cb_handler = ipcomp4_rcv_cb,
.err_handler = ipcomp4_err,
.priority = 0,
};
static int __init ipcomp4_init(void)
{
if (xfrm_register_type(&ipcomp_type, AF_INET) < 0) {
pr_info("%s: can't add xfrm type\n", __func__);
return -EAGAIN;
}
if (xfrm4_protocol_register(&ipcomp4_protocol, IPPROTO_COMP) < 0) {
pr_info("%s: can't add protocol\n", __func__);
xfrm_unregister_type(&ipcomp_type, AF_INET);
return -EAGAIN;
}
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
James Morris | 61 | 87.14% | 1 | 33.33% |
Joe Perches | 8 | 11.43% | 1 | 33.33% |
Steffen Klassert | 1 | 1.43% | 1 | 33.33% |
Total | 70 | 100.00% | 3 | 100.00% |
static void __exit ipcomp4_fini(void)
{
if (xfrm4_protocol_deregister(&ipcomp4_protocol, IPPROTO_COMP) < 0)
pr_info("%s: can't remove protocol\n", __func__);
if (xfrm_unregister_type(&ipcomp_type, AF_INET) < 0)
pr_info("%s: can't remove xfrm type\n", __func__);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
James Morris | 38 | 80.85% | 1 | 33.33% |
Joe Perches | 8 | 17.02% | 1 | 33.33% |
Steffen Klassert | 1 | 2.13% | 1 | 33.33% |
Total | 47 | 100.00% | 3 | 100.00% |
module_init(ipcomp4_init);
module_exit(ipcomp4_fini);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("IP Payload Compression Protocol (IPComp/IPv4) - RFC3173");
MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");
MODULE_ALIAS_XFRM_TYPE(AF_INET, XFRM_PROTO_COMP);
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Herbert Xu | 373 | 39.10% | 11 | 31.43% |
James Morris | 335 | 35.12% | 2 | 5.71% |
David S. Miller | 61 | 6.39% | 4 | 11.43% |
Steffen Klassert | 44 | 4.61% | 1 | 2.86% |
Jamal Hadi Salim | 41 | 4.30% | 1 | 2.86% |
Alexey Dobriyan | 39 | 4.09% | 3 | 8.57% |
Joe Perches | 16 | 1.68% | 1 | 2.86% |
Nicolas Dichtel | 12 | 1.26% | 1 | 2.86% |
Arnaldo Carvalho de Melo | 11 | 1.15% | 2 | 5.71% |
Masahide Nakamura | 9 | 0.94% | 2 | 5.71% |
Thomas Schlichter | 5 | 0.52% | 1 | 2.86% |
Eric Dumazet | 4 | 0.42% | 2 | 5.71% |
Mitsuru Kanda | 2 | 0.21% | 2 | 5.71% |
Hideaki Yoshifuji / 吉藤英明 | 1 | 0.10% | 1 | 2.86% |
Ian Morris | 1 | 0.10% | 1 | 2.86% |
Total | 954 | 100.00% | 35 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.