aboutsummaryrefslogtreecommitdiffstats
path: root/include/net/udplite.h
diff options
context:
space:
mode:
authorGerrit Renker <gerrit@erg.abdn.ac.uk>2006-11-27 14:10:57 -0500
committerDavid S. Miller <davem@sunset.davemloft.net>2006-12-03 00:22:46 -0500
commitba4e58eca8aa9473b44fdfd312f26c4a2e7798b3 (patch)
tree700f8f989f48da480beb83b983637cfd2b5a3f67 /include/net/udplite.h
parent6051e2f4fb68fc8e5343db58fa680ece376f405c (diff)
[NET]: Supporting UDP-Lite (RFC 3828) in Linux
This is a revision of the previously submitted patch, which alters the way files are organized and compiled in the following manner: * UDP and UDP-Lite now use separate object files * source file dependencies resolved via header files net/ipv{4,6}/udp_impl.h * order of inclusion files in udp.c/udplite.c adapted accordingly [NET/IPv4]: Support for the UDP-Lite protocol (RFC 3828) This patch adds support for UDP-Lite to the IPv4 stack, provided as an extension to the existing UDPv4 code: * generic routines are all located in net/ipv4/udp.c * UDP-Lite specific routines are in net/ipv4/udplite.c * MIB/statistics support in /proc/net/snmp and /proc/net/udplite * shared API with extensions for partial checksum coverage [NET/IPv6]: Extension for UDP-Lite over IPv6 It extends the existing UDPv6 code base with support for UDP-Lite in the same manner as per UDPv4. In particular, * UDPv6 generic and shared code is in net/ipv6/udp.c * UDP-Litev6 specific extensions are in net/ipv6/udplite.c * MIB/statistics support in /proc/net/snmp6 and /proc/net/udplite6 * support for IPV6_ADDRFORM * aligned the coding style of protocol initialisation with af_inet6.c * made the error handling in udpv6_queue_rcv_skb consistent; to return `-1' on error on all error cases * consolidation of shared code [NET]: UDP-Lite Documentation and basic XFRM/Netfilter support The UDP-Lite patch further provides * API documentation for UDP-Lite * basic xfrm support * basic netfilter support for IPv4 and IPv6 (LOG target) Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/net/udplite.h')
-rw-r--r--include/net/udplite.h149
1 files changed, 149 insertions, 0 deletions
diff --git a/include/net/udplite.h b/include/net/udplite.h
new file mode 100644
index 000000000000..1473b3e49044
--- /dev/null
+++ b/include/net/udplite.h
@@ -0,0 +1,149 @@
1/*
2 * Definitions for the UDP-Lite (RFC 3828) code.
3 */
4#ifndef _UDPLITE_H
5#define _UDPLITE_H
6
7/* UDP-Lite socket options */
8#define UDPLITE_SEND_CSCOV 10 /* sender partial coverage (as sent) */
9#define UDPLITE_RECV_CSCOV 11 /* receiver partial coverage (threshold ) */
10
11extern struct proto udplite_prot;
12extern struct hlist_head udplite_hash[UDP_HTABLE_SIZE];
13
14/* UDP-Lite does not have a standardized MIB yet, so we inherit from UDP */
15DECLARE_SNMP_STAT(struct udp_mib, udplite_statistics);
16
17/*
18 * Checksum computation is all in software, hence simpler getfrag.
19 */
20static __inline__ int udplite_getfrag(void *from, char *to, int offset,
21 int len, int odd, struct sk_buff *skb)
22{
23 return memcpy_fromiovecend(to, (struct iovec *) from, offset, len);
24}
25
26/* Designate sk as UDP-Lite socket */
27static inline int udplite_sk_init(struct sock *sk)
28{
29 udp_sk(sk)->pcflag = UDPLITE_BIT;
30 return 0;
31}
32
33/*
34 * Checksumming routines
35 */
36static inline int udplite_checksum_init(struct sk_buff *skb, struct udphdr *uh)
37{
38 u16 cscov;
39
40 /* In UDPv4 a zero checksum means that the transmitter generated no
41 * checksum. UDP-Lite (like IPv6) mandates checksums, hence packets
42 * with a zero checksum field are illegal. */
43 if (uh->check == 0) {
44 LIMIT_NETDEBUG(KERN_DEBUG "UDPLITE: zeroed checksum field\n");
45 return 1;
46 }
47
48 UDP_SKB_CB(skb)->partial_cov = 0;
49 cscov = ntohs(uh->len);
50
51 if (cscov == 0) /* Indicates that full coverage is required. */
52 cscov = skb->len;
53 else if (cscov < 8 || cscov > skb->len) {
54 /*
55 * Coverage length violates RFC 3828: log and discard silently.
56 */
57 LIMIT_NETDEBUG(KERN_DEBUG "UDPLITE: bad csum coverage %d/%d\n",
58 cscov, skb->len);
59 return 1;
60
61 } else if (cscov < skb->len)
62 UDP_SKB_CB(skb)->partial_cov = 1;
63
64 UDP_SKB_CB(skb)->cscov = cscov;
65
66 /*
67 * There is no known NIC manufacturer supporting UDP-Lite yet,
68 * hence ip_summed is always (re-)set to CHECKSUM_NONE.
69 */
70 skb->ip_summed = CHECKSUM_NONE;
71
72 return 0;
73}
74
75static __inline__ int udplite4_csum_init(struct sk_buff *skb, struct udphdr *uh)
76{
77 int rc = udplite_checksum_init(skb, uh);
78
79 if (!rc)
80 skb->csum = csum_tcpudp_nofold(skb->nh.iph->saddr,
81 skb->nh.iph->daddr,
82 skb->len, IPPROTO_UDPLITE, 0);
83 return rc;
84}
85
86static __inline__ int udplite6_csum_init(struct sk_buff *skb, struct udphdr *uh)
87{
88 int rc = udplite_checksum_init(skb, uh);
89
90 if (!rc)
91 skb->csum = ~csum_ipv6_magic(&skb->nh.ipv6h->saddr,
92 &skb->nh.ipv6h->daddr,
93 skb->len, IPPROTO_UDPLITE, 0);
94 return rc;
95}
96
97static inline int udplite_sender_cscov(struct udp_sock *up, struct udphdr *uh)
98{
99 int cscov = up->len;
100
101 /*
102 * Sender has set `partial coverage' option on UDP-Lite socket
103 */
104 if (up->pcflag & UDPLITE_SEND_CC) {
105 if (up->pcslen < up->len) {
106 /* up->pcslen == 0 means that full coverage is required,
107 * partial coverage only if 0 < up->pcslen < up->len */
108 if (0 < up->pcslen) {
109 cscov = up->pcslen;
110 }
111 uh->len = htons(up->pcslen);
112 }
113 /*
114 * NOTE: Causes for the error case `up->pcslen > up->len':
115 * (i) Application error (will not be penalized).
116 * (ii) Payload too big for send buffer: data is split
117 * into several packets, each with its own header.
118 * In this case (e.g. last segment), coverage may
119 * exceed packet length.
120 * Since packets with coverage length > packet length are
121 * illegal, we fall back to the defaults here.
122 */
123 }
124 return cscov;
125}
126
127static inline u32 udplite_csum_outgoing(struct sock *sk, struct sk_buff *skb)
128{
129 u32 csum = 0;
130 int off, len, cscov = udplite_sender_cscov(udp_sk(sk), skb->h.uh);
131
132 skb->ip_summed = CHECKSUM_NONE; /* no HW support for checksumming */
133
134 skb_queue_walk(&sk->sk_write_queue, skb) {
135 off = skb->h.raw - skb->data;
136 len = skb->len - off;
137
138 csum = skb_checksum(skb, off, (cscov > len)? len : cscov, csum);
139
140 if ((cscov -= len) <= 0)
141 break;
142 }
143 return csum;
144}
145
146extern void udplite4_register(void);
147extern int udplite_get_port(struct sock *sk, unsigned short snum,
148 int (*scmp)(const struct sock *, const struct sock *));
149#endif /* _UDPLITE_H */