Deleted Added
full compact
ip.c (50479) ip.c (50867)
1/*
2 * PPP IP Protocol Interface
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. 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 * PPP IP Protocol Interface
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. 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/ip.c 50479 1999-08-28 01:35:59Z peter $
20 * $FreeBSD: head/usr.sbin/ppp/ip.c 50867 1999-09-04 00:00:21Z brian $
21 *
22 * TODO:
23 * o Return ICMP message for filterd packet
24 * and optionaly record it into log.
25 */
26#include <sys/param.h>
27#if defined(__OpenBSD__) || defined(__NetBSD__)
28#include <sys/socket.h>

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

63#include "mp.h"
64#ifndef NORADIUS
65#include "radius.h"
66#endif
67#include "bundle.h"
68#include "tun.h"
69#include "ip.h"
70
21 *
22 * TODO:
23 * o Return ICMP message for filterd packet
24 * and optionaly record it into log.
25 */
26#include <sys/param.h>
27#if defined(__OpenBSD__) || defined(__NetBSD__)
28#include <sys/socket.h>

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

63#include "mp.h"
64#ifndef NORADIUS
65#include "radius.h"
66#endif
67#include "bundle.h"
68#include "tun.h"
69#include "ip.h"
70
71static const u_short interactive_ports[32] = {
72 544, 513, 514, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
73 80, 81, 0, 0, 0, 21, 22, 23, 0, 0, 0, 0, 0, 0, 0, 543,
74};
75
76#define INTERACTIVE(p) (interactive_ports[(p) & 0x1F] == (p))
77
78static const char *TcpFlags[] = { "FIN", "SYN", "RST", "PSH", "ACK", "URG" };
79
80static __inline int
81PortMatch(int op, u_short pport, u_short rport)
82{
83 switch (op) {
84 case OP_EQ:
85 return (pport == rport);

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

314PacketCheck(struct bundle *bundle, char *cp, int nb, struct filter *filter)
315{
316 struct ip *pip;
317 struct tcphdr *th;
318 struct udphdr *uh;
319 struct icmp *icmph;
320 char *ptop;
321 int mask, len, n;
71static const char *TcpFlags[] = { "FIN", "SYN", "RST", "PSH", "ACK", "URG" };
72
73static __inline int
74PortMatch(int op, u_short pport, u_short rport)
75{
76 switch (op) {
77 case OP_EQ:
78 return (pport == rport);

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

307PacketCheck(struct bundle *bundle, char *cp, int nb, struct filter *filter)
308{
309 struct ip *pip;
310 struct tcphdr *th;
311 struct udphdr *uh;
312 struct icmp *icmph;
313 char *ptop;
314 int mask, len, n;
322 int pri = PRI_NORMAL;
315 int pri = 0;
323 int logit, loglen;
324 char logbuf[200];
325
326 logit = log_IsKept(LogTCPIP) && filter->logok;
327 loglen = 0;
328
329 pip = (struct ip *) cp;
330

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

389 snprintf(logbuf + loglen, sizeof logbuf - loglen,
390 "%s:%d", inet_ntoa(pip->ip_dst), ntohs(uh->uh_dport));
391 loglen += strlen(logbuf + loglen);
392 }
393 break;
394 case IPPROTO_TCP:
395 th = (struct tcphdr *) ptop;
396 if (pip->ip_tos == IPTOS_LOWDELAY)
316 int logit, loglen;
317 char logbuf[200];
318
319 logit = log_IsKept(LogTCPIP) && filter->logok;
320 loglen = 0;
321
322 pip = (struct ip *) cp;
323

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

382 snprintf(logbuf + loglen, sizeof logbuf - loglen,
383 "%s:%d", inet_ntoa(pip->ip_dst), ntohs(uh->uh_dport));
384 loglen += strlen(logbuf + loglen);
385 }
386 break;
387 case IPPROTO_TCP:
388 th = (struct tcphdr *) ptop;
389 if (pip->ip_tos == IPTOS_LOWDELAY)
397 pri = PRI_FAST;
398 else if ((ntohs(pip->ip_off) & IP_OFFMASK) == 0) {
399 if (INTERACTIVE(ntohs(th->th_sport)) || INTERACTIVE(ntohs(th->th_dport)))
400 pri = PRI_FAST;
401 }
390 pri++;
391 else if ((ntohs(pip->ip_off) & IP_OFFMASK) == 0 &&
392 ipcp_IsUrgentPort(&bundle->ncp.ipcp, ntohs(th->th_sport),
393 ntohs(th->th_dport)))
394 pri++;
395
402 if (logit && loglen < sizeof logbuf) {
403 len = ntohs(pip->ip_len) - (pip->ip_hl << 2) - (th->th_off << 2);
404 snprintf(logbuf + loglen, sizeof logbuf - loglen,
405 "TCP: %s:%d ---> ", inet_ntoa(pip->ip_src), ntohs(th->th_sport));
406 loglen += strlen(logbuf + loglen);
407 snprintf(logbuf + loglen, sizeof logbuf - loglen,
408 "%s:%d", inet_ntoa(pip->ip_dst), ntohs(th->th_dport));
409 loglen += strlen(logbuf + loglen);

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

500 return NULL;
501}
502
503void
504ip_Enqueue(struct ipcp *ipcp, int pri, char *ptr, int count)
505{
506 struct mbuf *bp;
507
396 if (logit && loglen < sizeof logbuf) {
397 len = ntohs(pip->ip_len) - (pip->ip_hl << 2) - (th->th_off << 2);
398 snprintf(logbuf + loglen, sizeof logbuf - loglen,
399 "TCP: %s:%d ---> ", inet_ntoa(pip->ip_src), ntohs(th->th_sport));
400 loglen += strlen(logbuf + loglen);
401 snprintf(logbuf + loglen, sizeof logbuf - loglen,
402 "%s:%d", inet_ntoa(pip->ip_dst), ntohs(th->th_dport));
403 loglen += strlen(logbuf + loglen);

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

494 return NULL;
495}
496
497void
498ip_Enqueue(struct ipcp *ipcp, int pri, char *ptr, int count)
499{
500 struct mbuf *bp;
501
508 if (pri < 0 || pri > sizeof ipcp->Queue / sizeof ipcp->Queue[0])
502 if (pri < 0 || pri >= IPCP_QUEUES(ipcp))
509 log_Printf(LogERROR, "Can't store in ip queue %d\n", pri);
510 else {
511 /*
512 * We allocate an extra 6 bytes, four at the front and two at the end.
513 * This is an optimisation so that we need to do less work in
514 * mbuf_Prepend() in acf_LayerPush() and proto_LayerPush() and
515 * appending in hdlc_LayerPush().
516 */
517 bp = mbuf_Alloc(count + 6, MB_IPOUT);
518 bp->offset += 4;
519 bp->cnt -= 6;
520 memcpy(MBUF_CTOP(bp), ptr, count);
503 log_Printf(LogERROR, "Can't store in ip queue %d\n", pri);
504 else {
505 /*
506 * We allocate an extra 6 bytes, four at the front and two at the end.
507 * This is an optimisation so that we need to do less work in
508 * mbuf_Prepend() in acf_LayerPush() and proto_LayerPush() and
509 * appending in hdlc_LayerPush().
510 */
511 bp = mbuf_Alloc(count + 6, MB_IPOUT);
512 bp->offset += 4;
513 bp->cnt -= 6;
514 memcpy(MBUF_CTOP(bp), ptr, count);
521 mbuf_Enqueue(&ipcp->Queue[pri], bp);
515 mbuf_Enqueue(ipcp->Queue + pri, bp);
522 }
523}
524
525void
526ip_DeleteQueue(struct ipcp *ipcp)
527{
528 struct mqueue *queue;
529
516 }
517}
518
519void
520ip_DeleteQueue(struct ipcp *ipcp)
521{
522 struct mqueue *queue;
523
530 for (queue = ipcp->Queue; queue < ipcp->Queue + PRI_MAX; queue++)
524 for (queue = ipcp->Queue; queue < ipcp->Queue + IPCP_QUEUES(ipcp); queue++)
531 while (queue->top)
532 mbuf_Free(mbuf_Dequeue(queue));
533}
534
535int
536ip_QueueLen(struct ipcp *ipcp)
537{
538 struct mqueue *queue;
539 int result = 0;
540
525 while (queue->top)
526 mbuf_Free(mbuf_Dequeue(queue));
527}
528
529int
530ip_QueueLen(struct ipcp *ipcp)
531{
532 struct mqueue *queue;
533 int result = 0;
534
541 for (queue = ipcp->Queue; queue < ipcp->Queue + PRI_MAX; queue++)
535 for (queue = ipcp->Queue; queue < ipcp->Queue + IPCP_QUEUES(ipcp); queue++)
542 result += queue->qlen;
543
544 return result;
545}
546
547int
548ip_PushPacket(struct link *l, struct bundle *bundle)
549{
550 struct ipcp *ipcp = &bundle->ncp.ipcp;
551 struct mqueue *queue;
552 struct mbuf *bp;
553 struct ip *pip;
554 int cnt;
555
556 if (ipcp->fsm.state != ST_OPENED)
557 return 0;
558
536 result += queue->qlen;
537
538 return result;
539}
540
541int
542ip_PushPacket(struct link *l, struct bundle *bundle)
543{
544 struct ipcp *ipcp = &bundle->ncp.ipcp;
545 struct mqueue *queue;
546 struct mbuf *bp;
547 struct ip *pip;
548 int cnt;
549
550 if (ipcp->fsm.state != ST_OPENED)
551 return 0;
552
559 for (queue = &ipcp->Queue[PRI_FAST]; queue >= ipcp->Queue; queue--)
553 queue = ipcp->Queue + IPCP_QUEUES(ipcp) - 1;
554 do {
560 if (queue->top) {
561 bp = mbuf_Contiguous(mbuf_Dequeue(queue));
562 cnt = mbuf_Length(bp);
563 pip = (struct ip *)MBUF_CTOP(bp);
564 if (!FilterCheck(pip, &bundle->filter.alive))
565 bundle_StartIdleTimer(bundle);
555 if (queue->top) {
556 bp = mbuf_Contiguous(mbuf_Dequeue(queue));
557 cnt = mbuf_Length(bp);
558 pip = (struct ip *)MBUF_CTOP(bp);
559 if (!FilterCheck(pip, &bundle->filter.alive))
560 bundle_StartIdleTimer(bundle);
566 link_PushPacket(l, bp, bundle, PRI_NORMAL, PROTO_IP);
561 link_PushPacket(l, bp, bundle, 0, PROTO_IP);
567 ipcp_AddOutOctets(ipcp, cnt);
568 return 1;
569 }
562 ipcp_AddOutOctets(ipcp, cnt);
563 return 1;
564 }
565 } while (queue-- != ipcp->Queue);
570
571 return 0;
572}
566
567 return 0;
568}