]>
Commit | Line | Data |
---|---|---|
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 | ||
11 | extern struct proto udplite_prot; | |
12 | extern struct hlist_head udplite_hash[UDP_HTABLE_SIZE]; | |
13 | ||
14 | /* UDP-Lite does not have a standardized MIB yet, so we inherit from UDP */ | |
15 | DECLARE_SNMP_STAT(struct udp_mib, udplite_statistics); | |
16 | ||
17 | /* | |
18 | * Checksum computation is all in software, hence simpler getfrag. | |
19 | */ | |
20 | static __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 */ | |
27 | static 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 | */ | |
36 | static 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 | ||
75 | static __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 | ||
86 | static __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 | ||
97 | static 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 | ||
127 | static 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 | ||
146 | extern void udplite4_register(void); | |
147 | extern int udplite_get_port(struct sock *sk, unsigned short snum, | |
148 | int (*scmp)(const struct sock *, const struct sock *)); | |
149 | #endif /* _UDPLITE_H */ |