Ejemplo n.º 1
0
static int
WebSetCommand(Context ctx, int ac, char *av[], void *arg) 
{
  Web	 		w = &gWeb;
  int			port;

  switch ((intptr_t)arg) {

    case SET_OPEN:
      WebOpen(w);
      break;

    case SET_CLOSE:
      WebClose(w);
      break;

    case SET_ENABLE:
	EnableCommand(ac, av, &w->options, gConfList);
      break;

    case SET_DISABLE:
	DisableCommand(ac, av, &w->options, gConfList);
      break;

    case SET_SELF:
      if (ac < 1 || ac > 2)
	return(-1);

      if (!ParseAddr(av[0],&w->addr, ALLOW_IPV4)) 
	Error("Bogus IP address given %s", av[0]);

      if (ac == 2) {
        port =  strtol(av[1], NULL, 10);
        if (port < 1 || port > 65535)
	    Error("Bogus port given %s", av[1]);
        w->port=port;
      }
      break;

    default:
      return(-1);

  }

  return 0;
}
Ejemplo n.º 2
0
static int
Ipv6cpSetCommand(Context ctx, int ac, char *av[], void *arg)
{
	Ipv6cpState const ipv6cp = &ctx->bund->ipv6cp;

	if (ac == 0)
		return (-1);
	switch ((intptr_t)arg) {
	case SET_ACCEPT:
		AcceptCommand(ac, av, &ipv6cp->conf.options, gConfList);
		break;

	case SET_DENY:
		DenyCommand(ac, av, &ipv6cp->conf.options, gConfList);
		break;

	case SET_ENABLE:
		EnableCommand(ac, av, &ipv6cp->conf.options, gConfList);
		break;

	case SET_DISABLE:
		DisableCommand(ac, av, &ipv6cp->conf.options, gConfList);
		break;

	case SET_YES:
		YesCommand(ac, av, &ipv6cp->conf.options, gConfList);
		break;

	case SET_NO:
		NoCommand(ac, av, &ipv6cp->conf.options, gConfList);
		break;

	default:
		assert(0);
	}
	return (0);
}
Ejemplo n.º 3
0
static int
NatSetCommand(Context ctx, int ac, char *av[], void *arg)
{
  NatState	const nat = &ctx->bund->iface.nat;

  if (ac == 0)
    return(-1);
  switch ((intptr_t)arg) {
    case SET_TARGET:
#ifndef NG_NAT_LOG
	Error("Target address setting is unsupported by current kernel");
#endif
    /* FALL */
    case SET_ADDR:
      {
	struct u_addr	addr;

	/* Parse */
	if (ac != 1)
	  return(-1);
	if (!ParseAddr(av[0], &addr, ALLOW_IPV4))
	  Error("bad IP address \"%s\"", av[0]);

	/* OK */
	if ((intptr_t)arg == SET_ADDR) {
	    nat->alias_addr = addr;
	} else {
	    nat->target_addr = addr;
	}
      }
      break;

#ifdef NG_NAT_DESC_LENGTH
    case SET_REDIRECT_PORT:
      {
	struct protoent	*proto;
	struct in_addr	l_addr, a_addr, r_addr;
	int lp, ap, rp = 0, k;

	/* Parse */
	if (ac != 5 && ac != 7)
	  return(-1);
	if ((proto = getprotobyname(av[0])) == 0)
	  Error("bad PROTO name \"%s\"", av[0]);
	if (!inet_aton (av[1], &a_addr))
	  Error("bad alias IP address \"%s\"", av[1]);
	ap = atoi(av[2]);
	if (ap <= 0 || ap > 65535)
	  Error("Incorrect alias port number \"%s\"", av[2]);
	if (!inet_aton (av[3], &l_addr))
	  Error("bad local IP address \"%s\"", av[3]);
	lp = atoi(av[4]);
	if (lp <= 0 || lp > 65535)
	  Error("Incorrect local port number \"%s\"", av[4]);
	if (ac == 7) {
	  if (!inet_aton (av[5], &r_addr))
	    Error("bad remote IP address \"%s\"", av[5]);
	  rp = atoi(av[6]);
	  if (rp <= 0 || rp > 65535)
	    Error("Incorrect remote port number \"%s\"", av[6]);
	}
	/* OK */
	for (k=0;k<NM_PORT;k++) {
	  if (nat->nrpt_id[k] == 0) {
	    memcpy(&nat->nrpt[k].local_addr, &l_addr, sizeof(struct in_addr));
	    memcpy(&nat->nrpt[k].alias_addr, &a_addr, sizeof(struct in_addr));
	    nat->nrpt[k].local_port = lp;
	    nat->nrpt[k].alias_port = ap;
	    if (ac == 7) {
	      memcpy(&nat->nrpt[k].remote_addr, &r_addr, sizeof(struct in_addr));
	      nat->nrpt[k].remote_port = rp;
	    }
	    nat->nrpt[k].proto = (uint8_t)proto->p_proto;
	    snprintf(nat->nrpt[k].description, NG_NAT_DESC_LENGTH, "nat-port-%d", k);
	    nat->nrpt_id[k] = 1;
	    break;
	  }
	}
	if (k == NM_PORT)
	  Error("max number of redirect-port \"%d\" reached", NM_PORT);
      }
      break;

    case SET_REDIRECT_ADDR:
      {
	struct in_addr	l_addr, a_addr;
	int k;

	/* Parse */
	if (ac != 2)
	  return(-1);
	if (!inet_aton (av[0], &a_addr))
	  Error("bad alias IP address \"%s\"", av[0]);
	if (!inet_aton (av[1], &l_addr))
	  Error("bad local IP address \"%s\"", av[1]);

	/* OK */
	for (k=0;k<NM_ADDR;k++) {
	  if (nat->nrad_id[k] == 0) {
	    memcpy(&nat->nrad[k].local_addr, &l_addr, sizeof(struct in_addr));
	    memcpy(&nat->nrad[k].alias_addr, &a_addr, sizeof(struct in_addr));
	    snprintf(nat->nrad[k].description, NG_NAT_DESC_LENGTH, "nat-addr-%d", k);
	    nat->nrad_id[k] = 1;
	    break;
	  }
	}
	if (k == NM_ADDR)
	  Error("max number of redirect-addr \"%d\" reached", NM_ADDR);
      }
      break;

    case SET_REDIRECT_PROTO:
      {
	struct protoent	*proto;
	struct in_addr	l_addr, a_addr, r_addr;
	int k;

	/* Parse */
	if (ac != 3 && ac != 4)
	  return(-1);
	if ((proto = getprotobyname(av[0])) == 0)
	  Error("bad PROTO name \"%s\"", av[0]);
	if (!inet_aton (av[1], &a_addr))
	  Error("bad alias IP address \"%s\"", av[1]);
	if (!inet_aton (av[2], &l_addr))
	  Error("bad local IP address \"%s\"", av[2]);
	if (ac == 4) {
	  if (!inet_aton (av[3], &r_addr))
	    Error("bad remote IP address \"%s\"", av[3]);
	}

	/* OK */
	for (k=0;k<NM_PROTO;k++) {
	  if (nat->nrpr_id[k] == 0) {
	    memcpy(&nat->nrpr[k].local_addr, &l_addr, sizeof(struct in_addr));
	    memcpy(&nat->nrpr[k].alias_addr, &a_addr, sizeof(struct in_addr));
	    if (ac == 4)
	      memcpy(&nat->nrpr[k].remote_addr, &r_addr, sizeof(struct in_addr));
	    nat->nrpr[k].proto = (uint8_t)proto->p_proto;
	    snprintf(nat->nrpr[k].description, NG_NAT_DESC_LENGTH, "nat-proto-%d", k);
	    nat->nrpr_id[k] = 1;
	    break;
	  }
	}
	if (k == NM_PROTO)
	  Error("max number of redirect-proto \"%d\" reached", NM_PROTO);
      }
      break;
#endif

    case SET_ENABLE:
      EnableCommand(ac, av, &nat->options, gConfList);
      break;

    case SET_DISABLE:
      DisableCommand(ac, av, &nat->options, gConfList);
      break;

    default:
      assert(0);
  }
  return(0);
}
Ejemplo n.º 4
0
static int
IpcpSetCommand(Context ctx, int ac, char *av[], void *arg)
{
  IpcpState		const ipcp = &ctx->bund->ipcp;
  struct in_addr	*ips;

  if (ac == 0)
    return(-1);
  switch ((intptr_t)arg) {
    case SET_RANGES:
      {
	struct u_range	self_new_allow;
	struct u_range	peer_new_allow;
	int pos = 0, self_new_pool = -1, peer_new_pool = -1;

	/* Parse args */
	if (ac < 2)
	    return (-1);
	if (strcmp(av[pos], "ippool") == 0) {
	    self_new_pool = pos+1;
	    pos+=2;
	} else {
	    if (!ParseRange(av[pos], &self_new_allow, ALLOW_IPV4))
		return(-1);
	    pos++;
	}
	if (pos >= ac)
	    return (-1);
	if (strcmp(av[pos], "ippool") == 0) {
	    if ((pos + 1) >= ac)
		return (-1);
	    peer_new_pool = pos+1;
	    pos+=2;
	} else {
	    if (!ParseRange(av[pos], &peer_new_allow, ALLOW_IPV4))
		return(-1);
	    pos++;
	}
	if (pos != ac)
	    return (-1);

	if (self_new_pool >= 0)
	    strlcpy(ipcp->conf.self_ippool, av[self_new_pool], sizeof(ipcp->conf.self_ippool));
	else
	    ipcp->conf.self_ippool[0] = 0;
	if (peer_new_pool >= 0)
	    strlcpy(ipcp->conf.ippool, av[peer_new_pool], sizeof(ipcp->conf.ippool));
	else
	    ipcp->conf.ippool[0] = 0;
	ipcp->conf.self_allow = self_new_allow;
	ipcp->conf.peer_allow = peer_new_allow;

      }
      break;

    case SET_DNS:
      ips = ipcp->conf.peer_dns;
      goto getPrimSec;
      break;
    case SET_NBNS:
      ips = ipcp->conf.peer_nbns;
getPrimSec:
      if (!inet_aton(av[0], &ips[0]))
	Error("invalid IP address: \'%s\'", av[0]);
      ips[1].s_addr = 0;
      if (ac > 1 && !inet_aton(av[1], &ips[1]))
	Error("invalid IP address: \'%s\'", av[1]);
      break;

    case SET_ACCEPT:
      AcceptCommand(ac, av, &ipcp->conf.options, gConfList);
      break;

    case SET_DENY:
      DenyCommand(ac, av, &ipcp->conf.options, gConfList);
      break;

    case SET_ENABLE:
      EnableCommand(ac, av, &ipcp->conf.options, gConfList);
      break;

    case SET_DISABLE:
      DisableCommand(ac, av, &ipcp->conf.options, gConfList);
      break;

    case SET_YES:
      YesCommand(ac, av, &ipcp->conf.options, gConfList);
      break;

    case SET_NO:
      NoCommand(ac, av, &ipcp->conf.options, gConfList);
      break;

    default:
      assert(0);
  }
  return(0);
}