📄 ppp_vxworks.c
字号:
/* ppp_vxworks.c - System-dependent procedures for setting up PPP interfaces *//* Copyright 1995 Wind River Systems, Inc. */#include "copyright_wrs.h"/* * Copyright (c) 1989 Carnegie Mellon University. * All rights reserved. * * Redistribution and use in source and binary forms are permitted * provided that the above copyright notice and this paragraph are * duplicated in all such forms and that any documentation, * advertising materials, and other materials related to such * distribution and use acknowledge that the software was developed * by Carnegie Mellon University. The name of the * University may not be used to endorse or promote products derived * from this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. *//*modification history--------------------01h,17feb99,sgv Fixed spr 22486, Proxy Arp fix.01g,05aug96,vin upgraded to BSD4.4., replaced rtentry with ortentry, reworked get_ether_addr since ifreq struct changed. switched the order of initialization in sifaddr(). 01f,16jun95,dzb header file consolidation.01e,15may95,dzb changed LOG_ERR for route delete to LOG_WARNING.01d,06mar95,dzb proxyArp fix (SPR #4074).01c,07feb95,dzb changed to look for OK from pppwrite().01b,16jan95,dzb renamed to ppp_vxworks.c. warnings cleanup.01a,21dec94,dab VxWorks port - first WRS version. +dzb added: path for ppp header files, WRS copyright.*/#include "vxWorks.h"#include "string.h"#include "stdlib.h"#include "stdio.h"#include "ioctl.h"#include "ioLib.h"#include "sys/ioctl.h"#include "sys/types.h"#include "sys/socket.h"#include "sys/times.h"#include "net/if.h"#include "net/if_arp.h"#include "netinet/if_ether.h"#include "net/if_dl.h"#include "errno.h"#include "net/if.h"#include "net/route.h"#include "netinet/in.h"#include "pppLib.h"IMPORT struct ifnet *ifnet; /* list of all network interfaces *//* * establish_ppp - Turn the serial port into a ppp interface. */voidestablish_ppp(){ int x; /* get ppp fd */ if (ppptioctl(ppp_unit, PPPIOCGFD, (caddr_t) &(ppp_if[ppp_unit]->fd)) < 0) { syslog(LOG_ERR, "ppptioctl(PPPIOCGFD) error"); die(ppp_unit, 1); } /* * Enable debug in the driver if requested. */ if (ppp_if[ppp_unit]->kdebugflag) { if (ppptioctl(ppp_unit, PPPIOCGFLAGS, (caddr_t) &x) < 0) { syslog(LOG_WARNING, "ioctl (PPPIOCGFLAGS): error"); } else { x |= (ppp_if[ppp_unit]->kdebugflag & 0xFF) * SC_DEBUG; if (ppptioctl(ppp_unit, PPPIOCSFLAGS, (caddr_t) &x) < 0) syslog(LOG_WARNING, "ioctl(PPPIOCSFLAGS): error"); } }}/* * disestablish_ppp - Restore the serial port to normal operation. * This shouldn't call die() because it's called from die(). */voiddisestablish_ppp(){}/* * output - Output PPP packet. */voidoutput(unit, p, len) int unit; u_char *p; int len;{ if (ppp_if[unit]->debug) log_packet(p, len, "sent "); if (pppwrite(unit, (char *) p, len) != OK) { syslog(LOG_ERR, "write error"); die(unit, 1); }}/* * read_packet - get a PPP packet from the serial device. */intread_packet(buf) u_char *buf;{ int len; len = pppread(ppp_unit, (char *) buf, MTU + DLLHEADERLEN); if (len == 0) { MAINDEBUG((LOG_DEBUG, "read(fd): EWOULDBLOCK")); return -1; } return len;}/* * ppp_send_config - configure the transmit characteristics of * the ppp interface. */voidppp_send_config(unit, mtu, asyncmap, pcomp, accomp) int unit, mtu; u_long asyncmap; int pcomp, accomp;{ u_int x; if (ppptioctl(unit, SIOCSIFMTU, (caddr_t) &mtu) < 0) { syslog(LOG_ERR, "ioctl(SIOCSIFMTU) error"); die(unit, 1); } if (ppptioctl(unit, PPPIOCSASYNCMAP, (caddr_t) &asyncmap) < 0) { syslog(LOG_ERR, "ioctl(PPPIOCSASYNCMAP) error"); die(unit, 1); } if (ppptioctl(unit, PPPIOCGFLAGS, (caddr_t) &x) < 0) { syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS) error"); die(unit, 1); } x = pcomp? x | SC_COMP_PROT: x &~ SC_COMP_PROT; x = accomp? x | SC_COMP_AC: x &~ SC_COMP_AC; if (ppptioctl(unit, PPPIOCSFLAGS, (caddr_t) &x) < 0) { syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS) error"); die(unit, 1); }}/* * ppp_set_xaccm - set the extended transmit ACCM for the interface. */voidppp_set_xaccm(unit, accm) int unit; ext_accm accm;{ if (ppptioctl(unit, PPPIOCSXASYNCMAP, (caddr_t) accm) < 0) syslog(LOG_WARNING, "ioctl(set extended ACCM): error");}/* * ppp_recv_config - configure the receive-side characteristics of * the ppp interface. */voidppp_recv_config(unit, mru, asyncmap, pcomp, accomp) int unit, mru; u_long asyncmap; int pcomp, accomp;{ int x; if (ppptioctl(unit, PPPIOCSMRU, (caddr_t) &mru) < 0) { syslog(LOG_ERR, "ioctl(PPPIOCSMRU): error"); die(unit, 1); } if (ppptioctl(unit, PPPIOCSRASYNCMAP, (caddr_t) &asyncmap) < 0) { syslog(LOG_ERR, "ioctl(PPPIOCSRASYNCMAP): error"); die(unit, 1); } if (ppptioctl(unit, PPPIOCGFLAGS, (caddr_t) &x) < 0) { syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): error"); die(unit, 1); } x = !accomp? x | SC_REJ_COMP_AC: x &~ SC_REJ_COMP_AC; if (ppptioctl(unit, PPPIOCSFLAGS, (caddr_t) &x) < 0) { syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): error"); die(unit, 1); }}/* * sifvjcomp - config tcp header compression */intsifvjcomp(u, vjcomp, cidcomp, maxcid) int u, vjcomp, cidcomp, maxcid;{ u_int x; if (ppptioctl(u, PPPIOCGFLAGS, (caddr_t) &x) < 0) { syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS) error"); return 0; } x = vjcomp ? x | SC_COMP_TCP: x &~ SC_COMP_TCP; x = cidcomp? x & ~SC_NO_TCP_CCID: x | SC_NO_TCP_CCID; if (ppptioctl(u, PPPIOCSFLAGS, (caddr_t) &x) < 0) { syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS) error"); return 0; } if (ppptioctl(u, PPPIOCSMAXCID, (caddr_t) &maxcid) < 0) { syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): error"); return 0; } return 1;}/* * sifup - Config the interface up and enable IP packets to pass. */intsifup(u) int u;{ struct ifreq ifr; u_int x; strncpy(ifr.ifr_name, ppp_if[u]->ifname, sizeof (ifr.ifr_name)); if (ioctl(ppp_if[u]->s, SIOCGIFFLAGS, (int) &ifr) < 0) { syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS) error"); return 0; } ifr.ifr_flags |= IFF_UP; if (ioctl(ppp_if[u]->s, SIOCSIFFLAGS, (int) &ifr) < 0) { syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS) error"); return 0; } if (ppptioctl(u, PPPIOCGFLAGS, (caddr_t) &x) < 0) { syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): error"); return 0; } x |= SC_ENABLE_IP; if (ppptioctl(u, PPPIOCSFLAGS, (caddr_t) &x) < 0) { syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): error"); return 0; } return 1;}/* * sifdown - Config the interface down and disable IP. */intsifdown(u) int u;{ struct ifreq ifr; u_int x; int rv; rv = 1; if (ppptioctl(u, PPPIOCGFLAGS, (caddr_t) &x) < 0) { syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): error"); rv = 0; } else { x &= ~SC_ENABLE_IP; if (ppptioctl(u, PPPIOCSFLAGS, (caddr_t) &x) < 0) { syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): error"); rv = 0; } } strncpy(ifr.ifr_name, ppp_if[u]->ifname, sizeof (ifr.ifr_name)); if (ioctl(ppp_if[u]->s, SIOCGIFFLAGS, (int) &ifr) < 0) { syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS) error"); rv = 0; } else { ifr.ifr_flags &= ~IFF_UP; if (ioctl(ppp_if[u]->s, SIOCSIFFLAGS, (int) &ifr) < 0) { syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): error"); rv = 0; } } return rv;}/* * SET_SA_FAMILY - set the sa_family field of a struct sockaddr, * if it exists. */#define SET_SA_FAMILY(addr, family) \ BZERO((char *) &(addr), sizeof(addr)); \ addr.sa_family = (family); \ /* * sifaddr - Config the interface IP addresses and netmask. */intsifaddr(u, o, h, m) int u, o, h, m;{ struct ifreq ifr; strncpy(ifr.ifr_name, ppp_if[u]->ifname, sizeof(ifr.ifr_name)); SET_SA_FAMILY(ifr.ifr_addr, AF_INET); ifr.ifr_addr.sa_len = sizeof (struct sockaddr_in); if (m != 0) { ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = m; syslog(LOG_NOTICE, "Setting interface mask to %s", ip_ntoa(m)); if (ioctl(ppp_if[u]->s, SIOCSIFNETMASK, (int) &ifr) < 0) { syslog(LOG_ERR, "ioctl(SIOCSIFNETMASK): error"); return (0); } } SET_SA_FAMILY(ifr.ifr_dstaddr, AF_INET); ifr.ifr_dstaddr.sa_len = sizeof (struct sockaddr_in); ((struct sockaddr_in *) &ifr.ifr_dstaddr)->sin_addr.s_addr = h; if (ioctl(ppp_if[u]->s, SIOCSIFDSTADDR, (int) &ifr) < 0) { syslog(LOG_ERR, "ioctl(SIOCSIFDSTADDR): error"); return (0); } SET_SA_FAMILY(ifr.ifr_addr, AF_INET); ifr.ifr_addr.sa_len = sizeof (struct sockaddr_in); ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = o; if (ioctl(ppp_if[u]->s, SIOCSIFADDR, (int) &ifr) < 0) { syslog(LOG_ERR, "ioctl(SIOCSIFADDR): error"); return (0); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -