//Jesse struct subnet_record *make_normal_subnet( struct iface *iface )
struct subnet_record *make_normal_subnet( struct MIB_DHCP_s *iface )
{
	struct subnet_record *subrec;
	struct name_record *namerec;
	struct in_addr myip;
	struct in_addr bcast_ip;
	struct in_addr mask_ip;
	struct in_addr myip_temp;

//Jesse	myip.s_addr = iface->addr;
//Jesse	bcast_ip.s_addr = iface->broadcast;
//Jesse	mask_ip.s_addr = iface->netmask;
	myip.s_addr = iface->IPAddr;
	bcast_ip.s_addr = INADDR_BROADCAST;
	mask_ip.s_addr = iface->SubnetMask;
	myip_temp.s_addr = inet_address(iface->IPAddr);
	
//Jesse	subrec = make_subnet( (char *)inet_ntoa(iface->addr), NORMAL_SUBNET,
//Jesse			     myip, bcast_ip, mask_ip );
	subrec = make_subnet( (char *)inet_ntoa( myip_temp ), NORMAL_SUBNET,
							myip, bcast_ip, mask_ip );
	if(subrec)
		add_subnet(subrec);
	return subrec;
}
int create_subnets(void)
{
	struct in_addr unicast_ip;
//Jesse	struct iface *ifp;
	struct MIB_DHCP_s  *ifp;
	int i;
	
	// initialize subnetlsit
	for( i = 0; i < MAX_SUBNETS; i++ )
	{
		memset( &_subnetlist[i], 0, sizeof(_subnetlist[i]) );
		_subnetlist[i].bInUsed = FALSE;
	}

	/* 
	 * Create subnets from all the local interfaces and thread them onto
	 * the linked list. 
	 */

//Jesse	ifp = Lanface;
	ifp = mib_DHCP_p;
	if( !make_normal_subnet(ifp) )
		return FALSE;

	/* We should not be using a WINS server at all. Set the
		ip address of the subnet to be zero. */
	unicast_ip = ipzero;

	/*
	 * Create the unicast and remote broadcast subnets.
	 * Don't put these onto the linked list.
	 * The ip address of the unicast subnet is set to be
	 * the WINS server address, if it exists, or ipzero if not.
	 */

	unicast_subnet = make_subnet( "UNICAST_SUBNET", UNICAST_SUBNET, 
								   unicast_ip, unicast_ip, unicast_ip);

	remote_broadcast_subnet = make_subnet( "REMOTE_BROADCAST_SUBNET",
										REMOTE_BROADCAST_SUBNET,
										ipzero, ipzero, ipzero);

	if((unicast_subnet == NULL) || (remote_broadcast_subnet == NULL))
		return FALSE;

	return TRUE;
}
Beispiel #3
0
struct subnet_record *make_normal_subnet(struct interface *iface)
{
	struct subnet_record *subrec;

	subrec = make_subnet(inet_ntoa(iface->ip), NORMAL_SUBNET,
			     iface->ip, iface->bcast, iface->nmask);
	if (subrec) {
		add_subnet(subrec);
	}
	return subrec;
}
Beispiel #4
0
struct subnet_record *make_normal_subnet(const struct interface *iface)
{

	struct subnet_record *subrec;
	const struct in_addr *pip = &((const struct sockaddr_in *)&iface->ip)->sin_addr;
	const struct in_addr *pbcast = &((const struct sockaddr_in *)&iface->bcast)->sin_addr;
	const struct in_addr *pnmask = &((const struct sockaddr_in *)&iface->netmask)->sin_addr;

	subrec = make_subnet(inet_ntoa(*pip), NORMAL_SUBNET,
			     *pip, *pbcast, *pnmask);
	if (subrec) {
		add_subnet(subrec);
	}
	return subrec;
}
Beispiel #5
0
bool create_subnets(void)
{
	/* We only count IPv4 interfaces whilst we're waiting. */
	int num_interfaces;
	int i;
	struct in_addr unicast_ip, ipzero;

  try_interfaces_again:

	/* Only count IPv4, non-loopback interfaces. */
	if (iface_count_v4_nl() == 0) {
		DEBUG(0,("create_subnets: No local IPv4 non-loopback interfaces !\n"));
		DEBUG(0,("create_subnets: Waiting for an interface to appear ...\n"));
	}

	/* We only count IPv4, non-loopback interfaces here. */
	while (iface_count_v4_nl() == 0) {
		void (*saved_handler)(int);

		/*
		 * Whilst we're waiting for an interface, allow SIGTERM to
		 * cause us to exit.
		 */

		saved_handler = CatchSignal( SIGTERM, SIGNAL_CAST SIG_DFL );

		sleep(5);
		load_interfaces();

		/*
		 * We got an interface, restore our normal term handler.
		 */

		CatchSignal( SIGTERM, SIGNAL_CAST saved_handler );
	}

	/*
	 * Here we count v4 and v6 - we know there's at least one
	 * IPv4 interface and we filter on it below.
	 */
	num_interfaces = iface_count();

	/*
	 * Create subnets from all the local interfaces and thread them onto
	 * the linked list.
	 */

	for (i = 0 ; i < num_interfaces; i++) {
		const struct interface *iface = get_interface(i);

		if (!iface) {
			DEBUG(2,("create_subnets: can't get interface %d.\n", i ));
			continue;
		}

		/* Ensure we're only dealing with IPv4 here. */
		if (iface->ip.ss_family != AF_INET) {
			DEBUG(2,("create_subnets: "
				"ignoring non IPv4 interface.\n"));
			continue;
		}

		/*
		 * We don't want to add a loopback interface, in case
		 * someone has added 127.0.0.1 for smbd, nmbd needs to
		 * ignore it here. JRA.
		 */

		if (is_loopback_addr((struct sockaddr *)&iface->ip)) {
			DEBUG(2,("create_subnets: Ignoring loopback interface.\n" ));
			continue;
		}

		if (!make_normal_subnet(iface))
			return False;
	}

        /* We must have at least one subnet. */
	if (subnetlist == NULL) {
		void (*saved_handler)(int);

		DEBUG(0,("create_subnets: Unable to create any subnet from "
				"given interfaces. Is your interface line in "
				"smb.conf correct ?\n"));

		saved_handler = CatchSignal( SIGTERM, SIGNAL_CAST SIG_DFL );

		sleep(5);
		load_interfaces();

		CatchSignal( SIGTERM, SIGNAL_CAST saved_handler );
		goto try_interfaces_again;
	}

	if (lp_we_are_a_wins_server()) {
		/* Pick the first interface IPv4 address as the WINS server
		 * ip. */
		const struct in_addr *nip = first_ipv4_iface();

		if (!nip) {
			return False;
		}

		unicast_ip = *nip;
	} else {
		/* note that we do not set the wins server IP here. We just
			set it at zero and let the wins registration code cope
			with getting the IPs right for each packet */
		zero_ip_v4(&unicast_ip);
	}

	/*
	 * Create the unicast and remote broadcast subnets.
	 * Don't put these onto the linked list.
	 * The ip address of the unicast subnet is set to be
	 * the WINS server address, if it exists, or ipzero if not.
	 */

	unicast_subnet = make_subnet( "UNICAST_SUBNET", UNICAST_SUBNET, 
				unicast_ip, unicast_ip, unicast_ip);

	zero_ip_v4(&ipzero);

	remote_broadcast_subnet = make_subnet( "REMOTE_BROADCAST_SUBNET",
				REMOTE_BROADCAST_SUBNET,
				ipzero, ipzero, ipzero);

	if((unicast_subnet == NULL) || (remote_broadcast_subnet == NULL))
		return False;

	/* 
	 * If we are WINS server, create the WINS_SERVER_SUBNET - don't put on
	 * the linked list.
	 */

	if (lp_we_are_a_wins_server()) {
		if( (wins_server_subnet = make_subnet( "WINS_SERVER_SUBNET",
						WINS_SERVER_SUBNET, 
						ipzero, ipzero, ipzero )) == NULL )
			return False;
	}

	return True;
}
Beispiel #6
0
BOOL create_subnets(void)
{    
	int num_interfaces = iface_count();
	int i;
	struct in_addr unicast_ip, ipzero;

	if(num_interfaces == 0) {
		void (*saved_handler)(int);

		DEBUG(0,("create_subnets: No local interfaces !\n"));
		DEBUG(0,("create_subnets: Waiting for an interface to appear ...\n"));

		/* 
		 * Whilst we're waiting for an interface, allow SIGTERM to
		 * cause us to exit.
		 */

		saved_handler = CatchSignal( SIGTERM, SIGNAL_CAST SIG_DFL );

		while (iface_count() == 0) {
			sleep(5);
			load_interfaces();
		}

		/* 
		 * We got an interface, restore our normal term handler.
		 */

		CatchSignal( SIGTERM, SIGNAL_CAST saved_handler );
	}

	num_interfaces = iface_count();

	/* 
	 * Create subnets from all the local interfaces and thread them onto
	 * the linked list. 
	 */

	for (i = 0 ; i < num_interfaces; i++) {
		struct interface *iface = get_interface(i);

		if (!iface) {
			DEBUG(2,("create_subnets: can't get interface %d.\n", i ));
			continue;
		}

		/*
		 * We don't want to add a loopback interface, in case
		 * someone has added 127.0.0.1 for smbd, nmbd needs to
		 * ignore it here. JRA.
		 */

		if (ip_equal(iface->ip, loopback_ip)) {
			DEBUG(2,("create_subnets: Ignoring loopback interface.\n" ));
			continue;
		}

		if (!make_normal_subnet(iface))
			return False;
	}

        /* We must have at least one subnet. */
	if (subnetlist == NULL) {
		DEBUG(0,("create_subnets: unable to create any subnet from "
				"given interfaces. nmbd is terminating\n"));
		return False;
	}

	if (lp_we_are_a_wins_server()) {
		/* Pick the first interface ip address as the WINS server ip. */
		struct in_addr *nip = iface_n_ip(0);

		if (!nip) {
			return False;
		}

		unicast_ip = *nip;
	} else {
		/* note that we do not set the wins server IP here. We just
			set it at zero and let the wins registration code cope
			with getting the IPs right for each packet */
		zero_ip(&unicast_ip);
	}

	/*
	 * Create the unicast and remote broadcast subnets.
	 * Don't put these onto the linked list.
	 * The ip address of the unicast subnet is set to be
	 * the WINS server address, if it exists, or ipzero if not.
	 */

	unicast_subnet = make_subnet( "UNICAST_SUBNET", UNICAST_SUBNET, 
				unicast_ip, unicast_ip, unicast_ip);

	zero_ip(&ipzero);

	remote_broadcast_subnet = make_subnet( "REMOTE_BROADCAST_SUBNET",
				REMOTE_BROADCAST_SUBNET,
				ipzero, ipzero, ipzero);

	if((unicast_subnet == NULL) || (remote_broadcast_subnet == NULL))
		return False;

	/* 
	 * If we are WINS server, create the WINS_SERVER_SUBNET - don't put on
	 * the linked list.
	 */

	if (lp_we_are_a_wins_server()) {
		if( (wins_server_subnet = make_subnet( "WINS_SERVER_SUBNET",
						WINS_SERVER_SUBNET, 
						ipzero, ipzero, ipzero )) == NULL )
			return False;
	}

	return True;
}