|
|
1.1 ! root 1: /* ! 2: * udp line discipline; only one, to be pushed on /dev/ip17. ! 3: */ ! 4: ! 5: #include "udp.h" ! 6: #include "../h/param.h" ! 7: #include "../h/systm.h" ! 8: #include "../h/stream.h" ! 9: #include "../h/ttyio.h" ! 10: #include "../h/ttyld.h" ! 11: #include "../h/map.h" ! 12: #include "../h/buf.h" ! 13: /*#include "../h/ubavar.h"*/ ! 14: #include "../h/conf.h" ! 15: ! 16: #include "../h/inet/in.h" ! 17: #include "../h/inet/ip.h" ! 18: #include "../h/inet/ip_var.h" ! 19: #include "../h/inet/udp.h" ! 20: #include "../h/inet/udp_var.h" ! 21: #include "../h/inet/mbuf.h" ! 22: ! 23: struct queue *udpqueue; ! 24: ! 25: int udpopen(), udpiput(), udpisrv(), udpclose(); ! 26: int udposrv(), udpoput(); ! 27: static struct qinit udprinit = { udpiput, udpisrv, udpopen, udpclose, ! 28: UDP_MSG_LIMIT, 512 }; ! 29: static struct qinit udpwinit = { putq, udposrv, udpopen, udpclose, ! 30: UDP_MSG_LIMIT, 64 }; ! 31: struct streamtab udpinfo = { &udprinit, &udpwinit }; ! 32: ! 33: udpopen(q, dev) ! 34: register struct queue *q; ! 35: { ! 36: if (q->ptr) ! 37: return(0); ! 38: udpqueue = q; /* RD queue */ ! 39: q->flag |= QDELIM; ! 40: WR(q)->flag |= QDELIM; ! 41: q->ptr = (caddr_t)1; ! 42: WR(q)->ptr = (caddr_t)1; ! 43: q->flag |= QNOENB; /* ipiput calls qenable() */ ! 44: return(1); ! 45: } ! 46: ! 47: udpclose(q) ! 48: register struct queue *q; ! 49: { ! 50: if(udpqueue == q) ! 51: udpqueue = 0; ! 52: } ! 53: ! 54: udpisrv(q) ! 55: register struct queue *q; ! 56: { ! 57: register struct block *bp, *head, *tail; ! 58: ! 59: /* there is now a whole packet waiting ! 60: * on this queue; strip it off and pass to udp_input(). ! 61: * things other than data or delims are forwarded directly ! 62: * by udpiput(). ! 63: */ ! 64: head = tail = (struct block *) 0; ! 65: while(bp = getq(q)){ ! 66: if(bp->type == M_DELIM){ ! 67: freeb(bp); ! 68: if(head){ ! 69: MCHECK(head); ! 70: udp_input(head); ! 71: } else { ! 72: printf("udpisrv: no data\n"); ! 73: } ! 74: head = tail = (struct block *) 0; ! 75: } else if(bp->type == M_DATA){ ! 76: bp->next = (struct block *) 0; ! 77: if(head == (struct block *) 0){ ! 78: head = bp; ! 79: } else { ! 80: tail->next = bp; ! 81: } ! 82: tail = bp; ! 83: } else { ! 84: printf("udpisrv: weird type %d\n", bp->type); ! 85: (*q->next->qinfo->putp)(q->next, bp); ! 86: } ! 87: } ! 88: if (head) ! 89: bp_putback(q, head); ! 90: } ! 91: ! 92: ! 93: udpiput(q, bp) ! 94: register struct queue *q; ! 95: register struct block *bp; ! 96: { ! 97: switch(bp->type){ ! 98: case M_DATA: ! 99: putq(q, bp); /* putq does compression into blocks */ ! 100: break; ! 101: case M_DELIM: ! 102: putq(q, bp); ! 103: qenable(q); ! 104: break; ! 105: default: ! 106: (*q->next->qinfo->putp)(q->next, bp); ! 107: break; ! 108: } ! 109: ! 110: } ! 111: ! 112: udposrv(q) ! 113: register struct queue *q; ! 114: { ! 115: register union stmsg *sp; ! 116: register struct block *bp; ! 117: ! 118: while(bp = getq(q)){ ! 119: if(bp->type == M_IOCTL){ ! 120: (*q->next->qinfo->putp)(q->next, bp); ! 121: } else { ! 122: (*q->next->qinfo->putp)(q->next, bp); ! 123: } ! 124: } ! 125: } ! 126: ! 127: udp_ldout(bp) ! 128: register struct block *bp; ! 129: { ! 130: register struct block *bp1; ! 131: register struct queue *q; ! 132: ! 133: if(udpqueue == 0){ ! 134: bp_free(bp); ! 135: return(1); ! 136: } ! 137: q = WR(udpqueue); ! 138: if(q->next->flag&QFULL){ ! 139: printf("udp_ldout: QFULL\n"); ! 140: bp_free(bp); ! 141: return(1); ! 142: } ! 143: MCHECK(bp); ! 144: while(bp){ ! 145: bp1 = bp->next; ! 146: (*q->next->qinfo->putp)(q->next, bp); ! 147: bp = bp1; ! 148: } ! 149: /* ! 150: * send delim ! 151: */ ! 152: ! 153: putctl(q->next, M_DELIM); ! 154: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.