Deleted Added
full compact
vjcomp.c (50479) vjcomp.c (54912)
1/*
2 * Input/Output VJ Compressed packets
3 *
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
5 *
6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the Internet Initiative Japan, Inc. The name of the
14 * IIJ may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 *
1/*
2 * Input/Output VJ Compressed packets
3 *
4 * Written by Toshiharu OHNO (tony-o@iij.ad.jp)
5 *
6 * Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
7 *
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by the Internet Initiative Japan, Inc. The name of the
14 * IIJ may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 *
20 * $FreeBSD: head/usr.sbin/ppp/vjcomp.c 50479 1999-08-28 01:35:59Z peter $
20 * $FreeBSD: head/usr.sbin/ppp/vjcomp.c 54912 1999-12-20 20:29:47Z brian $
21 *
22 * TODO:
23 */
24#include <sys/param.h>
25#include <netinet/in.h>
26#include <netinet/in_systm.h>
27#include <netinet/ip.h>
28#include <sys/un.h>

--- 32 unchanged lines hidden (view full) ---

61static struct mbuf *
62vj_LayerPush(struct bundle *bundle, struct link *l, struct mbuf *bp, int pri,
63 u_short *proto)
64{
65 int type;
66 struct ip *pip;
67 u_short cproto = bundle->ncp.ipcp.peer_compproto >> 16;
68
21 *
22 * TODO:
23 */
24#include <sys/param.h>
25#include <netinet/in.h>
26#include <netinet/in_systm.h>
27#include <netinet/ip.h>
28#include <sys/un.h>

--- 32 unchanged lines hidden (view full) ---

61static struct mbuf *
62vj_LayerPush(struct bundle *bundle, struct link *l, struct mbuf *bp, int pri,
63 u_short *proto)
64{
65 int type;
66 struct ip *pip;
67 u_short cproto = bundle->ncp.ipcp.peer_compproto >> 16;
68
69 bp = mbuf_Contiguous(bp);
69 bp = m_pullup(bp);
70 pip = (struct ip *)MBUF_CTOP(bp);
71 if (*proto == PROTO_IP && pip->ip_p == IPPROTO_TCP &&
72 cproto == PROTO_VJCOMP) {
73 type = sl_compress_tcp(bp, pip, &bundle->ncp.ipcp.vj.cslc,
74 &bundle->ncp.ipcp.vj.slstat,
75 bundle->ncp.ipcp.peer_compproto & 0xff);
76 log_Printf(LogDEBUG, "vj_LayerWrite: type = %x\n", type);
77 switch (type) {
78 case TYPE_IP:
79 break;
80
81 case TYPE_UNCOMPRESSED_TCP:
82 *proto = PROTO_VJUNCOMP;
83 log_Printf(LogDEBUG, "vj_LayerPush: PROTO_IP -> PROTO_VJUNCOMP\n");
70 pip = (struct ip *)MBUF_CTOP(bp);
71 if (*proto == PROTO_IP && pip->ip_p == IPPROTO_TCP &&
72 cproto == PROTO_VJCOMP) {
73 type = sl_compress_tcp(bp, pip, &bundle->ncp.ipcp.vj.cslc,
74 &bundle->ncp.ipcp.vj.slstat,
75 bundle->ncp.ipcp.peer_compproto & 0xff);
76 log_Printf(LogDEBUG, "vj_LayerWrite: type = %x\n", type);
77 switch (type) {
78 case TYPE_IP:
79 break;
80
81 case TYPE_UNCOMPRESSED_TCP:
82 *proto = PROTO_VJUNCOMP;
83 log_Printf(LogDEBUG, "vj_LayerPush: PROTO_IP -> PROTO_VJUNCOMP\n");
84 mbuf_SetType(bp, MB_VJOUT);
84 m_settype(bp, MB_VJOUT);
85 break;
86
87 case TYPE_COMPRESSED_TCP:
88 *proto = PROTO_VJCOMP;
89 log_Printf(LogDEBUG, "vj_LayerPush: PROTO_IP -> PROTO_VJUNCOMP\n");
85 break;
86
87 case TYPE_COMPRESSED_TCP:
88 *proto = PROTO_VJCOMP;
89 log_Printf(LogDEBUG, "vj_LayerPush: PROTO_IP -> PROTO_VJUNCOMP\n");
90 mbuf_SetType(bp, MB_VJOUT);
90 m_settype(bp, MB_VJOUT);
91 break;
92
93 default:
94 log_Printf(LogERROR, "vj_LayerPush: Unknown frame type %x\n", type);
91 break;
92
93 default:
94 log_Printf(LogERROR, "vj_LayerPush: Unknown frame type %x\n", type);
95 mbuf_Free(bp);
95 m_freem(bp);
96 return NULL;
97 }
98 }
99
100 return bp;
101}
102
103static struct mbuf *
104VjUncompressTcp(struct ipcp *ipcp, struct mbuf *bp, u_char type)
105{
106 u_char *bufp;
107 int len, olen, rlen;
108 struct mbuf *nbp;
109 u_char work[MAX_HDR + MAX_VJHEADER]; /* enough to hold TCP/IP header */
110
96 return NULL;
97 }
98 }
99
100 return bp;
101}
102
103static struct mbuf *
104VjUncompressTcp(struct ipcp *ipcp, struct mbuf *bp, u_char type)
105{
106 u_char *bufp;
107 int len, olen, rlen;
108 struct mbuf *nbp;
109 u_char work[MAX_HDR + MAX_VJHEADER]; /* enough to hold TCP/IP header */
110
111 bp = mbuf_Contiguous(bp);
112 olen = len = mbuf_Length(bp);
111 bp = m_pullup(bp);
112 olen = len = m_length(bp);
113 if (type == TYPE_UNCOMPRESSED_TCP) {
114 /*
115 * Uncompressed packet does NOT change its size, so that we can use mbuf
116 * space for uncompression job.
117 */
118 bufp = MBUF_CTOP(bp);
119 len = sl_uncompress_tcp(&bufp, len, type, &ipcp->vj.cslc, &ipcp->vj.slstat,
120 (ipcp->my_compproto >> 8) & 255);
121 if (len <= 0) {
113 if (type == TYPE_UNCOMPRESSED_TCP) {
114 /*
115 * Uncompressed packet does NOT change its size, so that we can use mbuf
116 * space for uncompression job.
117 */
118 bufp = MBUF_CTOP(bp);
119 len = sl_uncompress_tcp(&bufp, len, type, &ipcp->vj.cslc, &ipcp->vj.slstat,
120 (ipcp->my_compproto >> 8) & 255);
121 if (len <= 0) {
122 mbuf_Free(bp);
122 m_freem(bp);
123 bp = NULL;
124 } else
123 bp = NULL;
124 } else
125 mbuf_SetType(bp, MB_VJIN);
125 m_settype(bp, MB_VJIN);
126 return bp;
127 }
128
129 /*
130 * Handle compressed packet. 1) Read upto MAX_VJHEADER bytes into work
131 * space. 2) Try to uncompress it. 3) Compute amount of necesary space. 4)
132 * Copy unread data info there.
133 */
134 if (len > MAX_VJHEADER)
135 len = MAX_VJHEADER;
136 rlen = len;
137 bufp = work + MAX_HDR;
138 bp = mbuf_Read(bp, bufp, rlen);
139 len = sl_uncompress_tcp(&bufp, olen, type, &ipcp->vj.cslc, &ipcp->vj.slstat,
140 (ipcp->my_compproto >> 8) & 255);
141 if (len <= 0) {
126 return bp;
127 }
128
129 /*
130 * Handle compressed packet. 1) Read upto MAX_VJHEADER bytes into work
131 * space. 2) Try to uncompress it. 3) Compute amount of necesary space. 4)
132 * Copy unread data info there.
133 */
134 if (len > MAX_VJHEADER)
135 len = MAX_VJHEADER;
136 rlen = len;
137 bufp = work + MAX_HDR;
138 bp = mbuf_Read(bp, bufp, rlen);
139 len = sl_uncompress_tcp(&bufp, olen, type, &ipcp->vj.cslc, &ipcp->vj.slstat,
140 (ipcp->my_compproto >> 8) & 255);
141 if (len <= 0) {
142 mbuf_Free(bp);
142 m_freem(bp);
143 return NULL;
144 }
145 len -= olen;
146 len += rlen;
143 return NULL;
144 }
145 len -= olen;
146 len += rlen;
147 nbp = mbuf_Alloc(len, MB_VJIN);
147 nbp = m_get(len, MB_VJIN);
148 memcpy(MBUF_CTOP(nbp), bufp, len);
148 memcpy(MBUF_CTOP(nbp), bufp, len);
149 mbuf_SetType(bp, MB_VJIN);
150 nbp->next = bp;
149 m_settype(bp, MB_VJIN);
150 nbp->m_next = bp;
151 return nbp;
152}
153
154static struct mbuf *
155vj_LayerPull(struct bundle *bundle, struct link *l, struct mbuf *bp,
156 u_short *proto)
157{
158 u_char type;

--- 32 unchanged lines hidden ---
151 return nbp;
152}
153
154static struct mbuf *
155vj_LayerPull(struct bundle *bundle, struct link *l, struct mbuf *bp,
156 u_short *proto)
157{
158 u_char type;

--- 32 unchanged lines hidden ---