2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include "../afs/param.h"
16 #include "../rx/rx_kcommon.h"
18 static struct protosw parent_proto; /* udp proto switch */
20 static void rxk_input(am, hlen)
21 register struct mbuf *am; {
22 register unsigned short *tsp;
25 register struct ip *ti;
30 struct sockaddr_in taddr;
33 int data_len, comp_sum;
34 /* make sure we have base ip and udp headers in first mbuf */
35 if (M_HASCL(am) || am->m_len < 28) {
36 am = m_pullup(am, 28);
39 hdr = (mtod(am, struct ip *))->ip_hl;
41 /* pull up more, the IP hdr is bigger than usual */
42 if (am->m_len < (8 + (hdr<<2))) {
43 am = m_pullup(am, 8+(hdr<<2));
46 ti = mtod(am, struct ip *); /* recompute, since m_pullup allocates new mbuf */
47 tu = (struct udphdr *)(((char *)ti) + (hdr<<2)); /* skip ip hdr */
49 ti = mtod(am, struct ip *);
50 tu = (struct udphdr *)(((char *)ti) + 20); /* skip basic ip hdr */
53 /* now read the port out */
56 for(tsp=rxk_ports, i=0; i<MAXRXPORTS;i++) {
63 /* if we get here, try to deliver packet to udp */
64 if (parent_proto.pr_input)
69 * the AIX version is complicated by the fact that the internet protocols
70 * are in a separate kernel extension, and they are unwilling to export their
71 * symbols to us. We can get there indirectly, however.
73 #include <net/netisr.h>
74 static struct ifqueue rxk_q; /* RXKluge queue */
75 static struct arpcom rxk_bogosity;
77 /* rxk_kpork - send pkt over to netwerk kporc for processing */
79 register struct mbuf *m;
81 find_input_type(0xdead, m, &rxk_bogosity, 0);
85 * AIX 4.3.3 changed the type of the second argument to
86 * ip_stripoptions(). The ip_stripoptions() prototype is in
87 * <netinet/proto_inet.h>. This header file also acquired a guard
88 * macro, _PROTO_INET_H_, at the same time. So we test for the guard
89 * macro to see which type we need to use for the second argument to
92 * This way we don't have to introduce a port just to compile AFS on AIX
96 #if defined(_PROTO_INET_H_) /* AIX 4.3.3 and presumably later */
97 #define STRIP_ARG2_TYPE unsigned long
98 #else /* AIX 4.3.2 and earlier */
99 #define STRIP_ARG2_TYPE struct mbuf *
102 void ip_stripoptions(struct mbuf *m, STRIP_ARG2_TYPE mopt)
104 struct ip *ip = mtod(m, struct ip *);
106 register caddr_t opts;
109 olen = (ip->ip_hl<<2) - sizeof (struct ip);
110 opts = (caddr_t)(ip + 1);
111 i = m->m_len - (sizeof (struct ip) + olen);
112 memcpy(opts, opts + olen, (unsigned)i);
114 if (m->m_flags & M_PKTHDR)
115 m->m_pkthdr.len -= olen;
116 ip->ip_hl = sizeof(struct ip) >> 2;
119 /* rxk_RX_input - RX pkt input process */
121 register struct mbuf *am; {
122 register unsigned short *tsp;
125 register struct ip *ti;
126 struct udpiphdr *tvu;
130 struct sockaddr_in taddr;
133 int data_len, comp_sum;
135 hdr = (ti = mtod(am, struct ip *))->ip_hl;
137 ip_stripoptions(am, 0); /* get rid of anything we don't need */
139 tu = (struct udphdr *)(((char *)ti) + 20);
141 * Make mbuf data length reflect UDP length.
142 * If not enough data to reflect UDP length, drop.
144 tvu = (struct udpiphdr *)ti;
145 tlen = ntohs((u_short)tvu->ui_ulen);
146 if ((int)ti->ip_len != tlen) {
147 if (tlen > (int)ti->ip_len) {
151 m_adj(am, tlen - (int)ti->ip_len);
153 /* deliver packet to rx */
154 taddr.sin_family = AF_INET; /* compute source address */
155 taddr.sin_port = tu->uh_sport;
156 taddr.sin_addr.s_addr = ti->ip_src.s_addr;
157 /* handle the checksum. Note that this code damages the actual ip
158 header (replacing it with the virtual one, which is the same size),
159 so we must ensure we get everything out we need, first */
160 if ( tu->uh_sum != 0) {
161 /* if the checksum is there, always check it. It's crazy not
162 * to, unless you can really be sure that your
163 * underlying network (and interfaces and drivers and
164 * DMA hardware, etc!) is error-free. First, fill
165 * in entire virtual ip header. */
169 tvu->ui_len = tvu->ui_ulen;
170 am->m_flags |= M_PKTHDR;
171 am->m_pkthdr.len = tlen;
172 if (in_cksum(am, sizeof(struct ip) + tlen)) {
173 /* checksum, including cksum field, doesn't come out 0, so
174 this packet is bad */
181 * 28 is IP (20) + UDP (8) header. ulen includes
182 * udp header, and we *don't* tell RX about udp
183 * header either. So, we remove those 8 as well.
185 data_len = ntohs(tu->uh_ulen);
187 if (!(*rxk_GetPacketProc)(&phandle, data_len)) {
188 if (rx_mb_to_packet(am, m_freem, 28, data_len, phandle)) {
189 /* XXX should just increment counter here.. */
190 printf("rx: truncated UDP packet\n");
191 rxi_FreePacket(phandle);
193 (*rxk_PacketArrivalProc)(phandle, &taddr, rx_socket, data_len);
198 /* rxk_isr - RX Kluge Input Service Routine */
200 register struct mbuf *m;
201 IFQ_LOCK_DECL(); /* silly macro has trailing ';'. Sigh. */
203 IF_DEQUEUE(&rxk_q, m);
210 * UDP fast timer to raise events for all but Solaris and NCR.
211 * Called about 5 times per second (at unknown priority?). Must go to
212 * splnet or obtain global lock before touching anything significant.
214 static void rxk_fasttimo (void)
219 /* do rx fasttimo processing here */
220 rxevent_RaiseEvents(&temp);
221 if (tproc = parent_proto.pr_fasttimo) (*tproc)();
227 register struct protosw *pr;
228 extern struct protosw *pffindproto();
231 (pr = pffindproto(AF_INET, IPPROTO_UDP, SOCK_DGRAM))) {
234 pr->pr_input = rxk_input;
235 pr->pr_fasttimo = rxk_fasttimo;
239 * don't bother with pr_drain and pr_ctlinput
240 * until we have something to do
242 rxk_q.ifq_maxlen = 128; /* obligatory XXX */
243 /* add pseudo pkt types as haque to get back onto net kproc */
244 if (!add_input_type(0xdead, NET_KPROC, rxk_isr, &rxk_q, NETISR_MAX-1))
249 printf("\nAFS: no INTERNET protocol support found\n");
255 void shutdown_rxkernel(void)
257 register struct protosw *pr;
259 extern struct protosw *pffindproto();
261 if (rxk_initDone && (pr = pffindproto(AF_INET, IPPROTO_UDP, SOCK_DGRAM))) {
265 for (i=0; i<MAXRXPORTS;i++) {
268 soclose((struct socket *)rxk_portRocks[i]);
269 rxk_portRocks[i] = (char *)0;
276 /* osi_NetSend - send asize bytes at adata from asocket to host at addr.
278 * Now, why do we allocate a new buffer when we could theoretically use the one
279 * pointed to by adata? Because PRU_SEND returns after queueing the message,
280 * not after sending it. If the sender changes the data after queueing it,
281 * we'd see the already-queued data change. One attempt to fix this without
282 * adding a copy would be to have this function wait until the datagram is
283 * sent; however this doesn't work well. In particular, if a host is down, and
284 * an ARP fails to that host, this packet will be queued until the ARP request
285 * comes back, which could be hours later. We can't block in this routine that
286 * long, since it prevents RPC timeouts from happening.
288 /* XXX In the brave new world, steal the data bufs out of the rx_packet iovec,
289 * and just queue those. XXX
292 osi_NetSend(asocket, addr, dvec, nvec, asize, istack)
293 register struct socket *asocket;
296 register afs_int32 asize;
297 struct sockaddr_in *addr;
300 register struct mbuf *tm, *um;
301 register afs_int32 code;
302 struct mbuf *top = 0;
303 register struct mbuf *m, **mp;
309 AFS_STATCNT(osi_NetSend);
310 #ifndef AFS_AIX41_ENV
312 * VRMIX has a version of sun's mclgetx() that works correctly with
313 * respect to mcopy(), so we can just dummy up the entire packet as
314 * an mbuf cluster, and pass it to the IP output routine (which will
315 * most likely have to frag it, but since mclgetx() has been fixed,
316 * will work ok). The only problem is that we have to wait until
317 * m_free() has been called on the cluster, to guarantee that we
318 * do not muck with it until it has gone out. We also must refrain
319 * from inadvertantly touching a piece of data that falls within the
320 * same cache line as any portion of the packet, if we have been lucky
321 * enough to be DMA-ing directly out from it.
322 * Certain IBM architects assure me that the rios is fast enough
323 * that the cost of the extra copy, as opposed to trying to
324 * DMA directly from the packet is barely worth my while,
325 * but I have a hard time accepting this.
327 * We can only use this code once we are passed in an indication of
328 * whether we are being called `process-synchronously' or not.
330 * of course, the packet must be pinned, which is currently true,
331 * but in future may not be.
336 tdata = dvec[0].iov_base;
337 tl = dvec[0].iov_len;
341 MGETHDR(m, M_DONTWAIT, MT_DATA);
344 MGET(m, M_DONTWAIT, MT_DATA);
348 /* can't get an mbuf, give up */
350 m_freem(top); /* free mbuf list we're building */
354 m->m_flags |= M_PKTHDR; /* XXX - temp */
356 m->m_pkthdr.rcvif = (struct ifnet *)0;
360 * WARNING: the `4 * MLEN' is somewhat dubious. It is better than
361 * `NBPG', which may have no relation to `CLBYTES'. Also,
362 * `CLBYTES' may be so large that we never use clusters,
363 * resulting in far too many mbufs being used. It is often
364 * better to briefly use a cluster, even if we are only using a
365 * portion of it. Since we are on the xmit side, it shouldn't
366 * end up sitting on a queue for a potentially unbounded time
367 * (except perhaps if we are talking to ourself).
369 if (asize >= (MHLEN + 3*MLEN)) {
370 MCLGET(m,M_DONTWAIT);
372 /* now compute usable size */
374 len = MIN(m->m_ext.ext_size, asize);
376 len = MIN(mlen, asize);
379 tpa = mtod(m, caddr_t);
385 memcpy(tpa, tdata, rlen);
390 top->m_pkthdr.len += rlen;
396 /* shouldn't come here! */
397 asize = 0; /* so we make progress toward completion */
400 tdata = dvec[i].iov_base;
401 tl = dvec[i].iov_len;
410 tm->m_act = (struct mbuf *) 0;
412 /* setup mbuf corresponding to destination address */
413 MGETHDR(um, M_DONTWAIT, MT_SONAME);
416 m_freem(top); /* free mbuf chain */
419 memcpy(mtod(um, caddr_t), addr, sizeof(*addr));
420 um->m_len = sizeof(*addr);
421 um->m_pkthdr.len = sizeof(*addr);
422 um->m_flags |= M_PKTHDR;
424 SOCKET_LOCK(asocket);
425 code = (*asocket->so_proto->pr_usrreq)(asocket, PRU_SEND, tm, um, 0);
426 SOCKET_UNLOCK(asocket);
434 #endif /* AFS_AIX41_ENV */