Ejemplo n.º 1
0
/**
 * init the onet once the iaddr has been obtained
 */
static int onet_init_post_iaddr( void )
{
	onet_t	*onet	= onet_main;
	int	err;

	// start the responder
	onet->resp = resp_start(&onet->local_cnxid, usercfg_get_auth_type(), onet_resp_accepted_cb, NULL);
	if( !onet->resp ){
		LOGM_CRIT("cant start onet's responder\n");
		return -1;
	}
	resp_set_label(onet->resp, "NeoIP_router tunnel");
	// publish the records for this router
	ns_util_publish_dns_hostname( NULL, usercfg_get_peername(), &onet->ip_iaddr, ONET_DNS_RECORD_TTL, NULL, NULL );
	ns_util_publish_dns_ip_addr( NULL, &onet->ip_iaddr, usercfg_get_peername(), ONET_DNS_RECORD_TTL, NULL, NULL );

	// open the virtual netif
	err = vdev_open( &onet->vdev );
	if( err ){
		LOGM_ERR("cant init vdev err=%d\n", err );
		return -1;
	}
	// set the mtu
	netif_set_mtu( onet->vdev.dev_name, 10000 );
	// register callback for the virtual netif
	vdev_register_callback( &onet->vdev, onet_vdev_in );
	// set the ip addr and netmask
	onet_set_ip_addr( &onet->ip_iaddr );
	onet_add_route_netmask( &onet->ip_netmask );

	// start the dnsgrab layer	
	if( prop_get_bool_dfl( "neoip_router", "debug:dnsgrab", 1 ) ){
		if( dnsgrab_start() ){
			LOGM_CRIT("cant start the dns grabber\n");
		}
		if( watchdog_open() ){
			LOGM_CRIT("cant start the watchdog\n");
		}
	}
	// add the handler in httpd
	httpd_handler_add( "/neoip_router", onet_httpd_handler_cb );
	return 0;
}
Ejemplo n.º 2
0
/*
 * demand_conf - configure the interface for doing dial-on-demand.
 */
void
demand_conf()
{
    int i;
    const struct protent *protp;

/*    framemax = lcp_allowoptions[0].mru;
    if (framemax < PPP_MRU) */
	framemax = PPP_MRU;
    framemax += PPP_HDRLEN + PPP_FCSLEN;
    frame = malloc(framemax);
    if (frame == NULL)
	novm("demand frame");
    framelen = 0;
    pend_q = NULL;
    escape_flag = 0;
    flush_flag = 0;
    fcs = PPP_INITFCS;

    netif_set_mtu(pcb, LWIP_MIN(lcp_allowoptions[0].mru, PPP_MRU));
    if (ppp_send_config(pcb, PPP_MRU, (u32_t) 0, 0, 0) < 0
	|| ppp_recv_config(pcb, PPP_MRU, (u32_t) 0, 0, 0) < 0)
	    fatal("Couldn't set up demand-dialled PPP interface: %m");

#ifdef PPP_FILTER
    set_filters(&pass_filter, &active_filter);
#endif

    /*
     * Call the demand_conf procedure for each protocol that's got one.
     */
    for (i = 0; (protp = protocols[i]) != NULL; ++i)
	if (protp->enabled_flag && protp->demand_conf != NULL)
	    ((*protp->demand_conf)(pcb));
/* FIXME: find a way to die() here */
#if 0
	    if (!((*protp->demand_conf)(pcb)))
		die(1);
#endif
}
Ejemplo n.º 3
0
/*
 * Make a new bundle or join us to an existing bundle
 * if we are doing multilink.
 */
int
mp_join_bundle()
{
	lcp_options *go = &lcp_gotoptions[0];
	lcp_options *ho = &lcp_hisoptions[0];
	lcp_options *ao = &lcp_allowoptions[0];
	int unit, pppd_pid;
	int l, mtu;
	char *p;
	TDB_DATA key, pid, rec;

	if (doing_multilink) {
		/* have previously joined a bundle */
		if (!go->neg_mrru || !ho->neg_mrru) {
			notice("oops, didn't get multilink on renegotiation");
			lcp_close(pcb, "multilink required");
			return 0;
		}
		/* XXX should check the peer_authname and ho->endpoint
		   are the same as previously */
		return 0;
	}

	if (!go->neg_mrru || !ho->neg_mrru) {
		/* not doing multilink */
		if (go->neg_mrru)
			notice("oops, multilink negotiated only for receive");
		mtu = ho->neg_mru? ho->mru: PPP_MRU;
		if (mtu > ao->mru)
			mtu = ao->mru;
		if (demand) {
			/* already have a bundle */
			cfg_bundle(0, 0, 0, 0);
			netif_set_mtu(pcb, mtu);
			return 0;
		}
		make_new_bundle(0, 0, 0, 0);
		set_ifunit(1);
		netif_set_mtu(pcb, mtu);
		return 0;
	}

	doing_multilink = 1;

	/*
	 * Find the appropriate bundle or join a new one.
	 * First we make up a name for the bundle.
	 * The length estimate is worst-case assuming every
	 * character has to be quoted.
	 */
	l = 4 * strlen(peer_authname) + 10;
	if (ho->neg_endpoint)
		l += 3 * ho->endpoint.length + 8;
	if (bundle_name)
		l += 3 * strlen(bundle_name) + 2;
	bundle_id = malloc(l);
	if (bundle_id == 0)
		novm("bundle identifier");

	p = bundle_id;
	p += slprintf(p, l-1, "BUNDLE=\"%q\"", peer_authname);
	if (ho->neg_endpoint || bundle_name)
		*p++ = '/';
	if (ho->neg_endpoint)
		p += slprintf(p, bundle_id+l-p, "%s",
			      epdisc_to_str(&ho->endpoint));
	if (bundle_name)
		p += slprintf(p, bundle_id+l-p, "/%v", bundle_name);

	/* Make the key for the list of links belonging to the bundle */
	l = p - bundle_id;
	blinks_id = malloc(l + 7);
	if (blinks_id == NULL)
		novm("bundle links key");
	slprintf(blinks_id, l + 7, "BUNDLE_LINKS=%s", bundle_id + 7);

	/*
	 * For demand mode, we only need to configure the bundle
	 * and attach the link.
	 */
	mtu = LWIP_MIN(ho->mrru, ao->mru);
	if (demand) {
		cfg_bundle(go->mrru, ho->mrru, go->neg_ssnhf, ho->neg_ssnhf);
		netif_set_mtu(pcb, mtu);
		script_setenv("BUNDLE", bundle_id + 7, 1);
		return 0;
	}

	/*
	 * Check if the bundle ID is already in the database.
	 */
	unit = -1;
	lock_db();
	key.dptr = bundle_id;
	key.dsize = p - bundle_id;
	pid = tdb_fetch(pppdb, key);
	if (pid.dptr != NULL) {
		/* bundle ID exists, see if the pppd record exists */
		rec = tdb_fetch(pppdb, pid);
		if (rec.dptr != NULL && rec.dsize > 0) {
			/* make sure the string is null-terminated */
			rec.dptr[rec.dsize-1] = 0;
			/* parse the interface number */
			parse_num(rec.dptr, "IFNAME=ppp", &unit);
			/* check the pid value */
			if (!parse_num(rec.dptr, "PPPD_PID=", &pppd_pid)
			    || !process_exists(pppd_pid)
			    || !owns_unit(pid, unit))
				unit = -1;
			free(rec.dptr);
		}
		free(pid.dptr);
	}

	if (unit >= 0) {
		/* attach to existing unit */
		if (bundle_attach(unit)) {
			set_ifunit(0);
			script_setenv("BUNDLE", bundle_id + 7, 0);
			make_bundle_links(1);
			unlock_db();
			info("Link attached to %s", ifname);
			return 1;
		}
		/* attach failed because bundle doesn't exist */
	}

	/* we have to make a new bundle */
	make_new_bundle(go->mrru, ho->mrru, go->neg_ssnhf, ho->neg_ssnhf);
	set_ifunit(1);
	netif_set_mtu(pcb, mtu);
	script_setenv("BUNDLE", bundle_id + 7, 1);
	make_bundle_links(pcb);
	unlock_db();
	info("New bundle %s created", ifname);
	multilink_master = 1;
	return 0;
}
Ejemplo n.º 4
0
static void send_config_pppol2tp(int mtu,
      u_int32_t asyncmap,
      int pcomp,
      int accomp)
{
 struct ifreq ifr;
 int on = 1;
 int fd;
 char reorderto[16];
 char tid[8];
 char sid[8];

 if (pppol2tp_ifname[0]) {
 struct ifreq ifr;
 int fd;

 fd = socket(AF_INET, SOCK_DGRAM, 0);
 if (fd >= 0) {
 memset (&ifr, '\0', sizeof (ifr));
 strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
 strlcpy(ifr.ifr_newname, pppol2tp_ifname,
 sizeof(ifr.ifr_name));
 ioctl(fd, SIOCSIFNAME, (caddr_t) &ifr);
 strlcpy(ifname, pppol2tp_ifname, 32);
 if (pppol2tp_debug_mask & PPPOL2TP_MSG_CONTROL) {
 dbglog("ppp%d: interface name %s",
       ifunit, ifname);
 }
 }
 close(fd);
 }

 if ((lcp_allowoptions[0].mru > 0) && (mtu > lcp_allowoptions[0].mru)) {
 warn("Overriding mtu %d to %d", mtu, lcp_allowoptions[0].mru);
 mtu = lcp_allowoptions[0].mru;
 }
 netif_set_mtu(ifunit, mtu);

 reorderto[0] = '\0';
 if (pppol2tp_reorder_timeout > 0)
 sprintf(&reorderto[0], "%d ", pppol2tp_reorder_timeout);
 tid[0] = '\0';
 if (pppol2tp_tunnel_id > 0)
 sprintf(&tid[0], "%hu ", pppol2tp_tunnel_id);
 sid[0] = '\0';
 if (pppol2tp_session_id > 0)
 sprintf(&sid[0], "%hu ", pppol2tp_session_id);

 dbglog("PPPoL2TP options: %s%s%s%s%s%s%s%s%sdebugmask %d",
       pppol2tp_recv_seq ? "recvseq " : "",
       pppol2tp_send_seq ? "sendseq " : "",
       pppol2tp_lns_mode ? "lnsmode " : "",
       pppol2tp_reorder_timeout ? "reorderto " : "", reorderto,
       pppol2tp_tunnel_id ? "tid " : "", tid,
       pppol2tp_session_id ? "sid " : "", sid,
       pppol2tp_debug_mask);

 if (pppol2tp_recv_seq)
 if (setsockopt(pppol2tp_fd, SOL_PPPOL2TP, PPPOL2TP_SO_RECVSEQ,
       &on, sizeof(on)) < 0)
 fatal("setsockopt(PPPOL2TP_RECVSEQ): %m");
 if (pppol2tp_send_seq)
 if (setsockopt(pppol2tp_fd, SOL_PPPOL2TP, PPPOL2TP_SO_SENDSEQ,
       &on, sizeof(on)) < 0)
 fatal("setsockopt(PPPOL2TP_SENDSEQ): %m");
 if (pppol2tp_lns_mode)
 if (setsockopt(pppol2tp_fd, SOL_PPPOL2TP, PPPOL2TP_SO_LNSMODE,
       &on, sizeof(on)) < 0)
 fatal("setsockopt(PPPOL2TP_LNSMODE): %m");
 if (pppol2tp_reorder_timeout)
 if (setsockopt(pppol2tp_fd, SOL_PPPOL2TP, PPPOL2TP_SO_REORDERTO,
       &pppol2tp_reorder_timeout,
       sizeof(pppol2tp_reorder_timeout)) < 0)
 fatal("setsockopt(PPPOL2TP_REORDERTO): %m");
 if (pppol2tp_debug_mask)
 if (setsockopt(pppol2tp_fd, SOL_PPPOL2TP, PPPOL2TP_SO_DEBUG,
       &pppol2tp_debug_mask, sizeof(pppol2tp_debug_mask)) < 0)
 fatal("setsockopt(PPPOL2TP_DEBUG): %m");
}