Ejemplo n.º 1
0
/********************************************************************
 *
 * clean_check - Fetch the flags for the device and generate
 * appropriate error messages.
 */
void clean_check(void)
{
    int x;
    char *s;

    if (still_ppp()) {
	if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) == 0) {
	    s = NULL;
	    switch (~x & (SC_RCV_B7_0|SC_RCV_B7_1|SC_RCV_EVNP|SC_RCV_ODDP)) {
	    case SC_RCV_B7_0:
		s = "all had bit 7 set to 1";
		break;

	    case SC_RCV_B7_1:
		s = "all had bit 7 set to 0";
		break;

	    case SC_RCV_EVNP:
		s = "all had odd parity";
		break;

	    case SC_RCV_ODDP:
		s = "all had even parity";
		break;
	    }

	    if (s != NULL) {
		warn("Receive serial link is not 8-bit clean:");
		warn("Problem: %s", s);
	    }
	}
    }
}
Ejemplo n.º 2
0
int cifaddr (int unit, int our_adr, int his_adr)
  {
    struct rtentry rt;
/*
 *  Delete the route through the device
 */
    memset (&rt, '\0', sizeof (rt));

    SET_SA_FAMILY (rt.rt_dst,     AF_INET);
    SET_SA_FAMILY (rt.rt_gateway, AF_INET);
    rt.rt_dev = ifname;  /* MJC */

    ((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = 0;
    ((struct sockaddr_in *) &rt.rt_dst)->sin_addr.s_addr     = his_adr;
    rt.rt_flags = RTF_UP | RTF_HOST;

    if (ioctl(sockfd, SIOCDELRT, &rt) < 0 && errno != ESRCH)
      {
	if (still_ppp())
	  {
	    syslog (LOG_ERR, "ioctl(SIOCDELRT) device route: %m");
	    return (0);
	  }
      }
    return 1;
  }
Ejemplo n.º 3
0
void ppp_recv_config (int unit,int mru,u_int32_t asyncmap,int pcomp,int accomp)
  {
    u_int x;

    MAINDEBUG ((LOG_DEBUG, "recv_config: mru = %d\n", mru));
/*
 * If we were called because the link has gone down then there is nothing
 * which may be done. Just return without incident.
 */
    if (!still_ppp())
      {
	return;
      }
/*
 * Set the receiver parameters
 */
    if (ioctl(fd, PPPIOCSMRU, (caddr_t) &mru) < 0)
      {
	syslog(LOG_ERR, "ioctl(PPPIOCSMRU): %m");
      }

    MAINDEBUG ((LOG_DEBUG, "recv_config: asyncmap = %lx\n", asyncmap));
    if (ioctl(fd, PPPIOCSRASYNCMAP, (caddr_t) &asyncmap) < 0)
      {
        syslog(LOG_ERR, "ioctl(PPPIOCSRASYNCMAP): %m");
	quit();
      }

    x = get_flags();
    x = accomp ? x & ~SC_REJ_COMP_AC : x | SC_REJ_COMP_AC;
    set_flags (x);
  }
Ejemplo n.º 4
0
void ccp_flags_set (int unit, int isopen, int isup)
{
    if (still_ppp()) {
	int x = get_flags(ppp_dev_fd);
	x = isopen? x | SC_CCP_OPEN : x &~ SC_CCP_OPEN;
	x = isup?   x | SC_CCP_UP   : x &~ SC_CCP_UP;
	set_flags (ppp_dev_fd, x);
    }
}
Ejemplo n.º 5
0
void ppp_send_config (int unit,int mtu,u_int32_t asyncmap,int pcomp,int accomp)
  {
    u_int x;
    struct ifreq ifr;
  
    MAINDEBUG ((LOG_DEBUG, "send_config: mtu = %d\n", mtu));
/*
 * Ensure that the link is still up.
 */
    if (still_ppp())
      {
/*
 * Set the MTU and other parameters for the ppp device
 */
	memset (&ifr, '\0', sizeof (ifr));
	strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
	ifr.ifr_mtu = mtu;
	
	if (ioctl(sockfd, SIOCSIFMTU, (caddr_t) &ifr) < 0)
	  {
	    syslog(LOG_ERR, "ioctl(SIOCSIFMTU): %m");
	    quit();
	  }
	
	MAINDEBUG ((LOG_DEBUG, "send_config: asyncmap = %lx\n", asyncmap));
	if (ioctl(fd, PPPIOCSASYNCMAP, (caddr_t) &asyncmap) < 0)
	  {
	    syslog(LOG_ERR, "ioctl(PPPIOCSASYNCMAP): %m");
	    quit();
	  }
    
	x = get_flags();
	x = pcomp  ? x | SC_COMP_PROT : x & ~SC_COMP_PROT;
	x = accomp ? x | SC_COMP_AC   : x & ~SC_COMP_AC;
	set_flags(x);
      }
  }
Ejemplo n.º 6
0
int cifdefaultroute (int unit, int gateway)
  {
    struct rtentry rt;

    if (has_default_route)
      {
	memset (&rt, '\0', sizeof (rt));
	SET_SA_FAMILY (rt.rt_dst,     AF_INET);
	SET_SA_FAMILY (rt.rt_gateway, AF_INET);
	((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = gateway;
    
	rt.rt_flags = RTF_UP | RTF_GATEWAY;
	if (ioctl(sockfd, SIOCDELRT, &rt) < 0 && errno != ESRCH)
	  {
	    if (still_ppp())
	      {
		syslog (LOG_ERR, "default route ioctl(SIOCDELRT): %m");
		return 0;
	      }
	  }
      }
    has_default_route = 0;
    return 1;
  }
Ejemplo n.º 7
0
void disestablish_ppp(void)
  {
    int x;
    char *s;
/*
 * Fetch the flags for the device and generate appropriate error
 * messages.
 */
    if (still_ppp() && initdisc >= 0)
      {
	if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) == 0)
	  {
	    s = NULL;
	    switch (~x & (SC_RCV_B7_0|SC_RCV_B7_1|SC_RCV_EVNP|SC_RCV_ODDP))
	      {
	      case SC_RCV_B7_0 | SC_RCV_B7_1 | SC_RCV_EVNP | SC_RCV_ODDP:
		s = "nothing was received";
		break;
		
	      case SC_RCV_B7_0:
	      case SC_RCV_B7_0 | SC_RCV_EVNP:
	      case SC_RCV_B7_0 | SC_RCV_ODDP:
	      case SC_RCV_B7_0 | SC_RCV_ODDP | SC_RCV_EVNP:
		s = "all had bit 7 set to 1";
		break;
		
	      case SC_RCV_B7_1:
	      case SC_RCV_B7_1 | SC_RCV_EVNP:
	      case SC_RCV_B7_1 | SC_RCV_ODDP:
	      case SC_RCV_B7_1 | SC_RCV_ODDP | SC_RCV_EVNP:
		s = "all had bit 7 set to 0";
		break;
		
	      case SC_RCV_EVNP:
		s = "all had odd parity";
		break;
		
	      case SC_RCV_ODDP:
		s = "all had even parity";
		break;
	      }
	    
	    if (s != NULL)
	      {
		syslog(LOG_WARNING, "Receive serial link is not"
		       " 8-bit clean:");
		syslog(LOG_WARNING, "Problem: %s", s);
	      }
	  }
	
	set_kdebugflag (prev_kdebugflag);
	
	if (ioctl(fd, TIOCSETD, &initdisc) < 0)
	  {
	    syslog(LOG_WARNING, "ioctl(TIOCSETD): %m");
	  }
	
	if (ioctl(fd, TIOCNXCL, 0) < 0)
	  {
	    syslog (LOG_WARNING, "ioctl(TIOCNXCL): %m");
	  }
      }
    initdisc = -1;
  }