ng_vjc.c (4cf49a43559ed9fdad601bdcccd2c55963008675) ng_vjc.c (bef9dae05a72866e79d97d9bff3fc5a2538b4421)
1
2/*
3 * ng_vjc.c
4 *
5 * Copyright (c) 1996-1999 Whistle Communications, Inc.
6 * All rights reserved.
7 *
8 * Subject to the following obligations and disclaimer of warranty, use and

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

92static int ng_vjc_rcvmsg(node_p node, struct ng_mesg *msg,
93 const char *retaddr, struct ng_mesg **resp);
94static int ng_vjc_rmnode(node_p node);
95static int ng_vjc_newhook(node_p node, hook_p hook, const char *name);
96static int ng_vjc_rcvdata(hook_p hook, struct mbuf *m, meta_p t);
97static int ng_vjc_disconnect(hook_p hook);
98
99/* Helper stuff */
1
2/*
3 * ng_vjc.c
4 *
5 * Copyright (c) 1996-1999 Whistle Communications, Inc.
6 * All rights reserved.
7 *
8 * Subject to the following obligations and disclaimer of warranty, use and

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

92static int ng_vjc_rcvmsg(node_p node, struct ng_mesg *msg,
93 const char *retaddr, struct ng_mesg **resp);
94static int ng_vjc_rmnode(node_p node);
95static int ng_vjc_newhook(node_p node, hook_p hook, const char *name);
96static int ng_vjc_rcvdata(hook_p hook, struct mbuf *m, meta_p t);
97static int ng_vjc_disconnect(hook_p hook);
98
99/* Helper stuff */
100static struct mbuf *pulluphdrs(struct mbuf *m);
100static struct mbuf *ng_vjc_pulluphdrs(struct mbuf *m);
101
102/* Node type descriptor */
103static struct ng_type typestruct = {
104 NG_VERSION,
105 NG_VJC_NODE_TYPE,
106 NULL,
107 ng_vjc_constructor,
108 ng_vjc_rcvmsg,

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

186 const priv_p priv = (priv_p) node->private;
187 struct ng_mesg *resp = NULL;
188 int error = 0;
189
190 /* Check type cookie */
191 switch (msg->header.typecookie) {
192 case NGM_VJC_COOKIE:
193 switch (msg->header.cmd) {
101
102/* Node type descriptor */
103static struct ng_type typestruct = {
104 NG_VERSION,
105 NG_VJC_NODE_TYPE,
106 NULL,
107 ng_vjc_constructor,
108 ng_vjc_rcvmsg,

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

186 const priv_p priv = (priv_p) node->private;
187 struct ng_mesg *resp = NULL;
188 int error = 0;
189
190 /* Check type cookie */
191 switch (msg->header.typecookie) {
192 case NGM_VJC_COOKIE:
193 switch (msg->header.cmd) {
194 case NGM_VJC_CONFIG:
194 case NGM_VJC_SET_CONFIG:
195 {
196 struct ngm_vjc_config *const c =
197 (struct ngm_vjc_config *) msg->data;
198
195 {
196 struct ngm_vjc_config *const c =
197 (struct ngm_vjc_config *) msg->data;
198
199 if (msg->header.arglen != sizeof(*c)
200 || c->numChannels > NG_VJC_MAX_CHANNELS
201 || c->numChannels < NG_VJC_MIN_CHANNELS)
199 if (msg->header.arglen != sizeof(*c))
202 ERROUT(EINVAL);
200 ERROUT(EINVAL);
203 if (priv->conf.enabled && c->enabled)
201 if ((priv->conf.enableComp || priv->conf.enableDecomp)
202 && (c->enableComp || c->enableDecomp))
204 ERROUT(EALREADY);
203 ERROUT(EALREADY);
205 if (c->enabled != 0) {
204 if (c->enableComp) {
205 if (c->numChannels > NG_VJC_MAX_CHANNELS
206 || c->numChannels < NG_VJC_MIN_CHANNELS)
207 ERROUT(EINVAL);
208 } else {
209 c->numChannels = NG_VJC_MAX_CHANNELS;
210 }
211 if (c->enableComp != 0 || c->enableDecomp != 0) {
206 bzero(&priv->slc, sizeof(priv->slc));
207 sl_compress_init(&priv->slc, c->numChannels);
208 }
209 priv->conf = *c;
210 break;
211 }
212 case NGM_VJC_GET_STATE:
213 NG_MKRESPONSE(resp, msg, sizeof(priv->slc), M_NOWAIT);

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

255{
256 const node_p node = hook->node;
257 const priv_p priv = (priv_p) node->private;
258 int error = 0;
259
260 if (hook == priv->ip) { /* outgoing packet */
261 u_int type;
262
212 bzero(&priv->slc, sizeof(priv->slc));
213 sl_compress_init(&priv->slc, c->numChannels);
214 }
215 priv->conf = *c;
216 break;
217 }
218 case NGM_VJC_GET_STATE:
219 NG_MKRESPONSE(resp, msg, sizeof(priv->slc), M_NOWAIT);

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

261{
262 const node_p node = hook->node;
263 const priv_p priv = (priv_p) node->private;
264 int error = 0;
265
266 if (hook == priv->ip) { /* outgoing packet */
267 u_int type;
268
263 if (!priv->conf.enabled) /* compression not enabled */
269 if (!priv->conf.enableComp) /* compression not enabled */
264 type = TYPE_IP;
265 else {
266 struct ip *ip;
267
270 type = TYPE_IP;
271 else {
272 struct ip *ip;
273
268 if ((m = pulluphdrs(m)) == NULL)
274 if ((m = ng_vjc_pulluphdrs(m)) == NULL)
269 ERROUT(ENOBUFS);
270 ip = mtod(m, struct ip *);
271 type = (ip->ip_p == IPPROTO_TCP) ?
272 sl_compress_tcp(m, ip,
273 &priv->slc, priv->conf.compressCID) : TYPE_IP;
274 }
275 switch (type) {
276 case TYPE_IP:

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

286 panic(__FUNCTION__);
287 }
288 } else if (hook == priv->vjcomp) { /* incoming compressed packet */
289 int vjlen;
290 u_int hlen;
291 u_char *hdr;
292 struct mbuf *mp;
293
275 ERROUT(ENOBUFS);
276 ip = mtod(m, struct ip *);
277 type = (ip->ip_p == IPPROTO_TCP) ?
278 sl_compress_tcp(m, ip,
279 &priv->slc, priv->conf.compressCID) : TYPE_IP;
280 }
281 switch (type) {
282 case TYPE_IP:

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

292 panic(__FUNCTION__);
293 }
294 } else if (hook == priv->vjcomp) { /* incoming compressed packet */
295 int vjlen;
296 u_int hlen;
297 u_char *hdr;
298 struct mbuf *mp;
299
294 /* Are we initialized? */
295 if (!priv->conf.enabled) {
300 /* Are we decompressing? */
301 if (!priv->conf.enableDecomp) {
296 m_freem(m);
297 m = NULL;
298 ERROUT(ENETDOWN);
299 }
300
301 /* Uncompress packet to reconstruct TCP/IP header */
302 m_freem(m);
303 m = NULL;
304 ERROUT(ENETDOWN);
305 }
306
307 /* Uncompress packet to reconstruct TCP/IP header */
302 if (!(m = m_pullup(m, MAX_VJHEADER)))
308 if (m->m_len < MAX_VJHEADER && !(m = m_pullup(m, MAX_VJHEADER)))
303 ERROUT(ENOBUFS);
304 vjlen = sl_uncompress_tcp_core(mtod(m, u_char *),
305 m->m_len, m->m_pkthdr.len, TYPE_COMPRESSED_TCP,
306 &priv->slc, &hdr, &hlen);
307 if (vjlen <= 0) {
308 m_freem(m);
309 m = NULL;
310 ERROUT(EINVAL);

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

337 mtod(mp, u_char *) + mp->m_len, m->m_len);
338 mp->m_len += m->m_len;
339 MFREE(m, mp->m_next);
340 } else
341 mp->m_next = m;
342 m = mp;
343 hook = priv->ip;
344 } else if (hook == priv->vjuncomp) { /* incoming uncompressed pkt */
309 ERROUT(ENOBUFS);
310 vjlen = sl_uncompress_tcp_core(mtod(m, u_char *),
311 m->m_len, m->m_pkthdr.len, TYPE_COMPRESSED_TCP,
312 &priv->slc, &hdr, &hlen);
313 if (vjlen <= 0) {
314 m_freem(m);
315 m = NULL;
316 ERROUT(EINVAL);

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

343 mtod(mp, u_char *) + mp->m_len, m->m_len);
344 mp->m_len += m->m_len;
345 MFREE(m, mp->m_next);
346 } else
347 mp->m_next = m;
348 m = mp;
349 hook = priv->ip;
350 } else if (hook == priv->vjuncomp) { /* incoming uncompressed pkt */
345 u_int hlen;
346 u_char *hdr;
351 u_char *hdr;
352 u_int hlen;
347
353
348 /* Are we initialized? */
349 if (!priv->conf.enabled) {
354 /* Are we decompressing? */
355 if (!priv->conf.enableDecomp) {
350 m_freem(m);
351 m = NULL;
352 ERROUT(ENETDOWN);
353 }
354
355 /* Run packet through uncompressor */
356 m_freem(m);
357 m = NULL;
358 ERROUT(ENETDOWN);
359 }
360
361 /* Run packet through uncompressor */
356 if ((m = pulluphdrs(m)) == NULL)
362 if ((m = ng_vjc_pulluphdrs(m)) == NULL)
357 ERROUT(ENOBUFS);
358 if (sl_uncompress_tcp_core(mtod(m, u_char *),
359 m->m_len, m->m_pkthdr.len, TYPE_UNCOMPRESSED_TCP,
360 &priv->slc, &hdr, &hlen) < 0) {
361 m_freem(m);
362 m = NULL;
363 ERROUT(EINVAL);
364 }

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

405 return (0);
406}
407
408/************************************************************************
409 HELPER STUFF
410 ************************************************************************/
411
412/*
363 ERROUT(ENOBUFS);
364 if (sl_uncompress_tcp_core(mtod(m, u_char *),
365 m->m_len, m->m_pkthdr.len, TYPE_UNCOMPRESSED_TCP,
366 &priv->slc, &hdr, &hlen) < 0) {
367 m_freem(m);
368 m = NULL;
369 ERROUT(EINVAL);
370 }

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

411 return (0);
412}
413
414/************************************************************************
415 HELPER STUFF
416 ************************************************************************/
417
418/*
413 * Pull up the full IP and TCP headers of a packet. This is optimized
414 * for the common case of standard length headers. If packet is not
419 * Pull up the full IP and TCP headers of a packet. If packet is not
415 * a TCP packet, just pull up the IP header.
416 */
417static struct mbuf *
420 * a TCP packet, just pull up the IP header.
421 */
422static struct mbuf *
418pulluphdrs(struct mbuf *m)
423ng_vjc_pulluphdrs(struct mbuf *m)
419{
420 struct ip *ip;
421 struct tcphdr *tcp;
422 int ihlen, thlen;
423
424{
425 struct ip *ip;
426 struct tcphdr *tcp;
427 int ihlen, thlen;
428
424 if ((m = m_pullup(m, sizeof(*ip) + sizeof(*tcp))) == NULL)
429 if (m->m_len < sizeof(*ip) && !(m = m_pullup(m, sizeof(*ip))))
425 return (NULL);
426 ip = mtod(m, struct ip *);
427 if (ip->ip_p != IPPROTO_TCP)
428 return (m);
430 return (NULL);
431 ip = mtod(m, struct ip *);
432 if (ip->ip_p != IPPROTO_TCP)
433 return (m);
429 if ((ihlen = (ip->ip_hl << 2)) != sizeof(*ip)) {
434 ihlen = ip->ip_hl << 2;
435 if (m->m_len < ihlen + sizeof(*tcp)) {
430 if (!(m = m_pullup(m, ihlen + sizeof(*tcp))))
431 return (NULL);
432 ip = mtod(m, struct ip *);
433 }
434 tcp = (struct tcphdr *) ((u_char *) ip + ihlen);
436 if (!(m = m_pullup(m, ihlen + sizeof(*tcp))))
437 return (NULL);
438 ip = mtod(m, struct ip *);
439 }
440 tcp = (struct tcphdr *) ((u_char *) ip + ihlen);
435 if ((thlen = (tcp->th_off << 2)) != sizeof(*tcp))
441 thlen = tcp->th_off << 2;
442 if (m->m_len < ihlen + thlen)
436 m = m_pullup(m, ihlen + thlen);
437 return (m);
438}
439
443 m = m_pullup(m, ihlen + thlen);
444 return (m);
445}
446