Blame view

include/net/udplite.h 3.75 KB
ba4e58eca   Gerrit Renker   [NET]: Supporting...
1
2
3
4
5
  /*
   *	Definitions for the UDP-Lite (RFC 3828) code.
   */
  #ifndef _UDPLITE_H
  #define _UDPLITE_H
6bb100b9f   David S. Miller   [UDPLite]: udplit...
6
  #include <net/ip6_checksum.h>
ba4e58eca   Gerrit Renker   [NET]: Supporting...
7
8
9
10
11
  /* UDP-Lite socket options */
  #define UDPLITE_SEND_CSCOV   10 /* sender partial coverage (as sent)      */
  #define UDPLITE_RECV_CSCOV   11 /* receiver partial coverage (threshold ) */
  
  extern struct proto 		udplite_prot;
645ca708f   Eric Dumazet   udp: introduce st...
12
  extern struct udp_table		udplite_table;
ba4e58eca   Gerrit Renker   [NET]: Supporting...
13

ba4e58eca   Gerrit Renker   [NET]: Supporting...
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
  /*
   *	Checksum computation is all in software, hence simpler getfrag.
   */
  static __inline__ int udplite_getfrag(void *from, char *to, int  offset,
  				      int len, int odd, struct sk_buff *skb)
  {
  	return memcpy_fromiovecend(to, (struct iovec *) from, offset, len);
  }
  
  /* Designate sk as UDP-Lite socket */
  static inline int udplite_sk_init(struct sock *sk)
  {
  	udp_sk(sk)->pcflag = UDPLITE_BIT;
  	return 0;
  }
  
  /*
   * 	Checksumming routines
   */
  static inline int udplite_checksum_init(struct sk_buff *skb, struct udphdr *uh)
  {
  	u16 cscov;
  
          /* In UDPv4 a zero checksum means that the transmitter generated no
           * checksum. UDP-Lite (like IPv6) mandates checksums, hence packets
           * with a zero checksum field are illegal.                            */
  	if (uh->check == 0) {
  		LIMIT_NETDEBUG(KERN_DEBUG "UDPLITE: zeroed checksum field
  ");
  		return 1;
  	}
ba4e58eca   Gerrit Renker   [NET]: Supporting...
45
46
47
  	cscov = ntohs(uh->len);
  
  	if (cscov == 0)		 /* Indicates that full coverage is required. */
759e5d006   Herbert Xu   [UDP]: Clean up U...
48
  		;
ba4e58eca   Gerrit Renker   [NET]: Supporting...
49
50
51
52
53
54
55
56
  	else if (cscov < 8  || cscov > skb->len) {
  		/*
  		 * Coverage length violates RFC 3828: log and discard silently.
  		 */
  		LIMIT_NETDEBUG(KERN_DEBUG "UDPLITE: bad csum coverage %d/%d
  ",
  			       cscov, skb->len);
  		return 1;
759e5d006   Herbert Xu   [UDP]: Clean up U...
57
  	} else if (cscov < skb->len) {
ba4e58eca   Gerrit Renker   [NET]: Supporting...
58
          	UDP_SKB_CB(skb)->partial_cov = 1;
759e5d006   Herbert Xu   [UDP]: Clean up U...
59
60
61
62
  		UDP_SKB_CB(skb)->cscov = cscov;
  		if (skb->ip_summed == CHECKSUM_COMPLETE)
  			skb->ip_summed = CHECKSUM_NONE;
          }
ba4e58eca   Gerrit Renker   [NET]: Supporting...
63
64
65
  
  	return 0;
  }
f36c23bb9   Gerrit Renker   udplite: fast-pat...
66
67
  /* Slow-path computation of checksum. Socket is locked. */
  static inline __wsum udplite_csum_outgoing(struct sock *sk, struct sk_buff *skb)
ba4e58eca   Gerrit Renker   [NET]: Supporting...
68
  {
f36c23bb9   Gerrit Renker   udplite: fast-pat...
69
  	const struct udp_sock *up = udp_sk(skb->sk);
ba4e58eca   Gerrit Renker   [NET]: Supporting...
70
  	int cscov = up->len;
f36c23bb9   Gerrit Renker   udplite: fast-pat...
71
  	__wsum csum = 0;
ba4e58eca   Gerrit Renker   [NET]: Supporting...
72

f36c23bb9   Gerrit Renker   udplite: fast-pat...
73
74
75
76
77
  	if (up->pcflag & UDPLITE_SEND_CC) {
  		/*
  		 * Sender has set `partial coverage' option on UDP-Lite socket.
  		 * The special case "up->pcslen == 0" signifies full coverage.
  		 */
ba4e58eca   Gerrit Renker   [NET]: Supporting...
78
  		if (up->pcslen < up->len) {
f36c23bb9   Gerrit Renker   udplite: fast-pat...
79
80
81
  			if (0 < up->pcslen)
  				cscov = up->pcslen;
  			udp_hdr(skb)->len = htons(up->pcslen);
ba4e58eca   Gerrit Renker   [NET]: Supporting...
82
  		}
f36c23bb9   Gerrit Renker   udplite: fast-pat...
83
84
85
86
87
88
89
90
91
92
  		/*
  		 * NOTE: Causes for the error case  `up->pcslen > up->len':
  		 *        (i)  Application error (will not be penalized).
  		 *       (ii)  Payload too big for send buffer: data is split
  		 *             into several packets, each with its own header.
  		 *             In this case (e.g. last segment), coverage may
  		 *             exceed packet length.
  		 *       Since packets with coverage length > packet length are
  		 *       illegal, we fall back to the defaults here.
  		 */
ba4e58eca   Gerrit Renker   [NET]: Supporting...
93
  	}
ba4e58eca   Gerrit Renker   [NET]: Supporting...
94
95
96
97
  
  	skb->ip_summed = CHECKSUM_NONE;     /* no HW support for checksumming */
  
  	skb_queue_walk(&sk->sk_write_queue, skb) {
ea2ae17d6   Arnaldo Carvalho de Melo   [SK_BUFF]: Introd...
98
99
  		const int off = skb_transport_offset(skb);
  		const int len = skb->len - off;
ba4e58eca   Gerrit Renker   [NET]: Supporting...
100
101
102
103
104
105
106
107
  
  		csum = skb_checksum(skb, off, (cscov > len)? len : cscov, csum);
  
  		if ((cscov -= len) <= 0)
  			break;
  	}
  	return csum;
  }
f36c23bb9   Gerrit Renker   udplite: fast-pat...
108
  /* Fast-path computation of checksum. Socket may not be locked. */
f6b9664f8   Herbert Xu   udp: Switch to ip...
109
110
  static inline __wsum udplite_csum(struct sk_buff *skb)
  {
f36c23bb9   Gerrit Renker   udplite: fast-pat...
111
  	const struct udp_sock *up = udp_sk(skb->sk);
f6b9664f8   Herbert Xu   udp: Switch to ip...
112
  	const int off = skb_transport_offset(skb);
f36c23bb9   Gerrit Renker   udplite: fast-pat...
113
  	int len = skb->len - off;
f6b9664f8   Herbert Xu   udp: Switch to ip...
114

f36c23bb9   Gerrit Renker   udplite: fast-pat...
115
116
117
118
119
  	if ((up->pcflag & UDPLITE_SEND_CC) && up->pcslen < len) {
  		if (0 < up->pcslen)
  			len = up->pcslen;
  		udp_hdr(skb)->len = htons(up->pcslen);
  	}
f6b9664f8   Herbert Xu   udp: Switch to ip...
120
  	skb->ip_summed = CHECKSUM_NONE;     /* no HW support for checksumming */
f36c23bb9   Gerrit Renker   udplite: fast-pat...
121
  	return skb_checksum(skb, off, len, 0);
f6b9664f8   Herbert Xu   udp: Switch to ip...
122
  }
ba4e58eca   Gerrit Renker   [NET]: Supporting...
123
124
  extern void	udplite4_register(void);
  extern int 	udplite_get_port(struct sock *sk, unsigned short snum,
df2bc459a   David S. Miller   [UDP]: Revert 2-p...
125
  			int (*scmp)(const struct sock *, const struct sock *));
ba4e58eca   Gerrit Renker   [NET]: Supporting...
126
  #endif	/* _UDPLITE_H */