summaryrefslogtreecommitdiffstats
path: root/source/nmbd
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2007-10-10 18:25:16 -0700
committerJeremy Allison <jra@samba.org>2007-10-10 18:25:16 -0700
commit3f6bd0e1ec5cc6670f3d08f76fc2cd94c9cd1a08 (patch)
tree4ff3c1569e665db6b2d70044f057c5bc1dbdc4c0 /source/nmbd
parent3f1ac564c0ab6d498a47da84b4b5744d8d376f3b (diff)
downloadsamba-3f6bd0e1ec5cc6670f3d08f76fc2cd94c9cd1a08.tar.gz
samba-3f6bd0e1ec5cc6670f3d08f76fc2cd94c9cd1a08.tar.xz
samba-3f6bd0e1ec5cc6670f3d08f76fc2cd94c9cd1a08.zip
Add start of IPv6 implementation. Currently most of this is avoiding
IPv6 in winbindd, but moves most of the socket functions that were wrongly in lib/util.c into lib/util_sock.c and provides generic IPv4/6 independent versions of most things. Still lots of work to do, but now I can see how I'll fix the access check code. Nasty part that remains is the name resolution code which is used to returning arrays of in_addr structs. Jeremy.
Diffstat (limited to 'source/nmbd')
-rw-r--r--source/nmbd/nmbd.c55
-rw-r--r--source/nmbd/nmbd_become_dmb.c20
-rw-r--r--source/nmbd/nmbd_browsesync.c8
-rw-r--r--source/nmbd/nmbd_incomingrequests.c6
-rw-r--r--source/nmbd/nmbd_lmhosts.c2
-rw-r--r--source/nmbd/nmbd_logonnames.c2
-rw-r--r--source/nmbd/nmbd_namequery.c2
-rw-r--r--source/nmbd/nmbd_packets.c54
-rw-r--r--source/nmbd/nmbd_processlogon.c21
-rw-r--r--source/nmbd/nmbd_subnetdb.c50
-rw-r--r--source/nmbd/nmbd_synclists.c2
-rw-r--r--source/nmbd/nmbd_winsproxy.c2
-rw-r--r--source/nmbd/nmbd_winsserver.c4
-rw-r--r--source/nmbd/nmbd_workgroupdb.c2
14 files changed, 149 insertions, 81 deletions
diff --git a/source/nmbd/nmbd.c b/source/nmbd/nmbd.c
index dc03506194b..f0de0b8485f 100644
--- a/source/nmbd/nmbd.c
+++ b/source/nmbd/nmbd.c
@@ -27,7 +27,6 @@ int ClientDGRAM = -1;
int global_nmb_port = -1;
extern BOOL rescan_listen_set;
-extern struct in_addr loopback_ip;
extern BOOL global_in_nmbd;
extern BOOL override_logfile;
@@ -192,33 +191,49 @@ static BOOL reload_interfaces(time_t t)
/* find any interfaces that need adding */
for (n=iface_count() - 1; n >= 0; n--) {
- struct interface *iface = get_interface(n);
+ char str[INET6_ADDRSTRLEN];
+ const struct interface *iface = get_interface(n);
+ struct in_addr ip, nmask;
if (!iface) {
DEBUG(2,("reload_interfaces: failed to get interface %d\n", n));
continue;
}
+ /* Ensure we're only dealing with IPv4 here. */
+ if (iface->ip.ss_family != AF_INET) {
+ DEBUG(2,("reload_interfaces: "
+ "ignoring non IPv4 interface.\n"));
+ continue;
+ }
+
+ ip = ((struct sockaddr_in *)&iface->ip)->sin_addr;
+ nmask = ((struct sockaddr_in *)&iface->netmask)->sin_addr;
+
/*
* 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,("reload_interfaces: Ignoring loopback interface %s\n", inet_ntoa(iface->ip)));
+ if (is_loopback_addr(&iface->ip)) {
+ DEBUG(2,("reload_interfaces: Ignoring loopback "
+ "interface %s\n",
+ print_sockaddr(str, sizeof(str),
+ &iface->ip, sizeof(iface->ip)) ));
continue;
}
for (subrec=subnetlist; subrec; subrec=subrec->next) {
- if (ip_equal(iface->ip, subrec->myip) &&
- ip_equal(iface->nmask, subrec->mask_ip)) break;
+ if (ip_equal(ip, subrec->myip) &&
+ ip_equal(nmask, subrec->mask_ip)) break;
}
if (!subrec) {
/* it wasn't found! add it */
DEBUG(2,("Found new interface %s\n",
- inet_ntoa(iface->ip)));
+ print_sockaddr(str, sizeof(str),
+ &iface->ip, sizeof(iface->ip)) ));
subrec = make_normal_subnet(iface);
if (subrec)
register_my_workgroup_one_subnet(subrec);
@@ -229,8 +244,20 @@ static BOOL reload_interfaces(time_t t)
for (subrec=subnetlist; subrec; subrec=subrec->next) {
for (n=iface_count() - 1; n >= 0; n--) {
struct interface *iface = get_interface(n);
- if (ip_equal(iface->ip, subrec->myip) &&
- ip_equal(iface->nmask, subrec->mask_ip)) break;
+ struct in_addr ip, nmask;
+ if (!iface) {
+ continue;
+ }
+ /* Ensure we're only dealing with IPv4 here. */
+ if (iface->ip.ss_family != AF_INET) {
+ DEBUG(2,("reload_interfaces: "
+ "ignoring non IPv4 interface.\n"));
+ continue;
+ }
+ ip = ((struct sockaddr_in *)&iface->ip)->sin_addr;
+ nmask = ((struct sockaddr_in *)&iface->netmask)->sin_addr;
+ if (ip_equal(ip, subrec->myip) &&
+ ip_equal(nmask, subrec->mask_ip)) break;
}
if (n == -1) {
/* oops, an interface has disapeared. This is
@@ -322,7 +349,9 @@ static void msg_nmbd_send_packet(struct messaging_context *msg,
{
struct packet_struct *p = (struct packet_struct *)data->data;
struct subnet_record *subrec;
- struct in_addr *local_ip;
+ struct sockaddr_storage ss;
+ const struct sockaddr_storage *pss;
+ const struct in_addr *local_ip;
DEBUG(10, ("Received send_packet from %d\n", procid_to_pid(&src)));
@@ -339,14 +368,16 @@ static void msg_nmbd_send_packet(struct messaging_context *msg,
return;
}
- local_ip = iface_ip(p->ip);
+ in_addr_to_sockaddr_storage(&ss, p->ip);
+ pss = iface_ip(&ss);
- if (local_ip == NULL) {
+ if (pss == NULL) {
DEBUG(2, ("Could not find ip for packet from %d\n",
procid_to_pid(&src)));
return;
}
+ local_ip = &((const struct sockaddr_in *)pss)->sin_addr;
subrec = FIRST_SUBNET;
p->fd = (p->packet_type == NMB_PACKET) ?
diff --git a/source/nmbd/nmbd_become_dmb.c b/source/nmbd/nmbd_become_dmb.c
index a0250f205a8..fb87927436d 100644
--- a/source/nmbd/nmbd_become_dmb.c
+++ b/source/nmbd/nmbd_become_dmb.c
@@ -22,8 +22,6 @@
#include "includes.h"
-extern struct in_addr allones_ip;
-
extern uint16 samba_nb_type; /* Samba's NetBIOS type. */
static void become_domain_master_browser_bcast(const char *);
@@ -119,7 +117,7 @@ in workgroup %s on subnet %s\n",
if( subrec == unicast_subnet ) {
struct nmb_name nmbname;
struct in_addr my_first_ip;
- struct in_addr *nip;
+ const struct in_addr *nip;
/* Put our name and first IP address into the
workgroup struct as domain master browser. This
@@ -129,14 +127,14 @@ in workgroup %s on subnet %s\n",
make_nmb_name(&nmbname, global_myname(), 0x20);
work->dmb_name = nmbname;
- /* Pick the first interface ip address as the domain master browser ip. */
- nip = iface_n_ip(0);
+ /* Pick the first interface IPv4 address as the domain master browser ip. */
+ nip = first_ipv4_iface();
if (!nip) {
- DEBUG(0,("become_domain_master_stage2: Error. iface_n_ip returned NULL\n"));
+ DEBUG(0,("become_domain_master_stage2: "
+ "Error. get_interface returned NULL\n"));
return;
}
-
my_first_ip = *nip;
putip((char *)&work->dmb_addr, &my_first_ip);
@@ -204,10 +202,12 @@ workgroup %s on subnet %s\n", wg_name, subrec->subnet_name));
static void become_domain_master_query_success(struct subnet_record *subrec,
struct userdata_struct *userdata,
- struct nmb_name *nmbname, struct in_addr ip,
+ struct nmb_name *nmbname, struct in_addr ip,
struct res_rec *rrec)
{
unstring name;
+ struct in_addr allones_ip;
+
pull_ascii_nstring(name, sizeof(name), nmbname->name);
/* If the given ip is not ours, then we can't become a domain
@@ -217,7 +217,9 @@ static void become_domain_master_query_success(struct subnet_record *subrec,
/* BUG note. Samba 1.9.16p11 servers seem to return the broadcast
address or zero ip for this query. Pretend this is ok. */
- if(ismyip(ip) || ip_equal(allones_ip, ip) || is_zero_ip(ip)) {
+ allones_ip.s_addr = htonl(INADDR_BROADCAST);
+
+ if(ismyip_v4(ip) || ip_equal(allones_ip, ip) || is_zero_ip_v4(ip)) {
if( DEBUGLVL( 3 ) ) {
dbgtext( "become_domain_master_query_success():\n" );
dbgtext( "Our address (%s) ", inet_ntoa(ip) );
diff --git a/source/nmbd/nmbd_browsesync.c b/source/nmbd/nmbd_browsesync.c
index 2e12f72b33d..e141b3e288e 100644
--- a/source/nmbd/nmbd_browsesync.c
+++ b/source/nmbd/nmbd_browsesync.c
@@ -103,7 +103,7 @@ static void announce_local_master_browser_to_domain_master_browser( struct work_
unstring dmb_name;
char *p;
- if(ismyip(work->dmb_addr)) {
+ if(ismyip_v4(work->dmb_addr)) {
if( DEBUGLVL( 2 ) ) {
dbgtext( "announce_local_master_browser_to_domain_master_browser:\n" );
dbgtext( "We are both a domain and a local master browser for " );
@@ -291,7 +291,7 @@ static void find_domain_master_name_query_success(struct subnet_record *subrec,
/* First check if we already have a dmb for this workgroup. */
- if(!is_zero_ip(work->dmb_addr) && ip_equal(work->dmb_addr, answer_ip)) {
+ if(!is_zero_ip_v4(work->dmb_addr) && ip_equal(work->dmb_addr, answer_ip)) {
/* Do the local master browser announcement to the domain
master browser name and IP. */
announce_local_master_browser_to_domain_master_browser( work );
@@ -300,7 +300,7 @@ static void find_domain_master_name_query_success(struct subnet_record *subrec,
sync_with_dmb(work);
return;
} else {
- zero_ip(&work->dmb_addr);
+ zero_ip_v4(&work->dmb_addr);
}
/* Now initiate the node status request. */
@@ -526,7 +526,7 @@ static void find_all_domain_master_names_query_success(struct subnet_record *sub
* Don't send node status requests to ourself.
*/
- if(ismyip( send_ip )) {
+ if(ismyip_v4( send_ip )) {
if( DEBUGLVL( 5 ) ) {
dbgtext( "find_all_domain_master_names_query_succes:\n" );
dbgtext( "Not sending node status to our own IP " );
diff --git a/source/nmbd/nmbd_incomingrequests.c b/source/nmbd/nmbd_incomingrequests.c
index 956d0ab1e91..292a580ef9b 100644
--- a/source/nmbd/nmbd_incomingrequests.c
+++ b/source/nmbd/nmbd_incomingrequests.c
@@ -88,7 +88,7 @@ subnet %s from owner IP %s\n",
subrec->subnet_name, inet_ntoa(owner_ip)));
/* If someone is releasing a broadcast group name, just ignore it. */
- if( group && !ismyip(owner_ip) )
+ if( group && !ismyip_v4(owner_ip) )
return;
/*
@@ -98,7 +98,7 @@ subnet %s from owner IP %s\n",
*/
pull_ascii_nstring(qname, sizeof(qname), question->name);
- if( !group && !ismyip(owner_ip) && strequal(qname, lp_workgroup()) &&
+ if( !group && !ismyip_v4(owner_ip) && strequal(qname, lp_workgroup()) &&
((question->name_type == 0x0) || (question->name_type == 0x1e))) {
DEBUG(6,("process_name_release_request: FTP OnNet bug workaround. Ignoring \
group release name %s from IP %s on subnet %s with no group bit set.\n",
@@ -497,7 +497,7 @@ void process_name_query_request(struct subnet_record *subrec, struct packet_stru
if (namerec->data.source == WINS_PROXY_NAME) {
for( i = 0; i < namerec->data.num_ips; i++) {
- if (same_net(namerec->data.ip[i], subrec->myip, subrec->mask_ip)) {
+ if (same_net_v4(namerec->data.ip[i], subrec->myip, subrec->mask_ip)) {
DEBUG(5,("process_name_query_request: name %s is a WINS proxy name and is also on the same subnet (%s) as the requestor. Not replying.\n",
nmb_namestr(&namerec->name), subrec->subnet_name ));
return;
diff --git a/source/nmbd/nmbd_lmhosts.c b/source/nmbd/nmbd_lmhosts.c
index 4785df6cba2..eba73294188 100644
--- a/source/nmbd/nmbd_lmhosts.c
+++ b/source/nmbd/nmbd_lmhosts.c
@@ -48,7 +48,7 @@ void load_lmhosts_file(const char *fname)
/* We find a relevent subnet to put this entry on, then add it. */
/* Go through all the broadcast subnets and see if the mask matches. */
for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
- if(same_net(ipaddr, subrec->bcast_ip, subrec->mask_ip))
+ if(same_net_v4(ipaddr, subrec->bcast_ip, subrec->mask_ip))
break;
}
diff --git a/source/nmbd/nmbd_logonnames.c b/source/nmbd/nmbd_logonnames.c
index 71b69ebd873..f0350af3b81 100644
--- a/source/nmbd/nmbd_logonnames.c
+++ b/source/nmbd/nmbd_logonnames.c
@@ -22,8 +22,6 @@
#include "includes.h"
-extern struct in_addr allones_ip;
-
extern uint16 samba_nb_type; /* Samba's NetBIOS type. */
/****************************************************************************
diff --git a/source/nmbd/nmbd_namequery.c b/source/nmbd/nmbd_namequery.c
index 4dcae87220a..ea170d3aaa3 100644
--- a/source/nmbd/nmbd_namequery.c
+++ b/source/nmbd/nmbd_namequery.c
@@ -35,7 +35,7 @@ static void query_name_response( struct subnet_record *subrec,
struct nmb_name *question_name = &rrec->packet->packet.nmb.question.question_name;
struct in_addr answer_ip;
- zero_ip(&answer_ip);
+ zero_ip_v4(&answer_ip);
/* Ensure we don't retry the query but leave the response record cleanup
to the timeout code. We may get more answer responses in which case
diff --git a/source/nmbd/nmbd_packets.c b/source/nmbd/nmbd_packets.c
index 875e13fdc88..cb13febe466 100644
--- a/source/nmbd/nmbd_packets.c
+++ b/source/nmbd/nmbd_packets.c
@@ -28,8 +28,6 @@ extern int global_nmb_port;
extern int num_response_packets;
-extern struct in_addr loopback_ip;
-
static void queue_packet(struct packet_struct *packet);
BOOL rescan_listen_set = False;
@@ -148,7 +146,7 @@ static BOOL send_netbios_packet(struct packet_struct *p)
BOOL loopback_this_packet = False;
/* Check if we are sending to or from ourselves as a WINS server. */
- if(ismyip(p->ip) && (p->port == global_nmb_port))
+ if(ismyip_v4(p->ip) && (p->port == global_nmb_port))
loopback_this_packet = True;
if(loopback_this_packet) {
@@ -225,12 +223,12 @@ static struct packet_struct *create_and_init_netbios_packet(struct nmb_name *nmb
static BOOL create_and_init_additional_record(struct packet_struct *packet,
uint16 nb_flags,
- struct in_addr *register_ip)
+ const struct in_addr *register_ip)
{
struct nmb_packet *nmb = &packet->packet.nmb;
if((nmb->additional = SMB_MALLOC_P(struct res_rec)) == NULL) {
- DEBUG(0,("initiate_name_register_packet: malloc fail for additional record.\n"));
+ DEBUG(0,("create_and_init_additional_record: malloc fail for additional record.\n"));
return False;
}
@@ -316,7 +314,7 @@ static BOOL initiate_name_query_packet_from_wins_server( struct packet_struct *p
**************************************************************************/
static BOOL initiate_name_register_packet( struct packet_struct *packet,
- uint16 nb_flags, struct in_addr *register_ip)
+ uint16 nb_flags, const struct in_addr *register_ip)
{
struct nmb_packet *nmb = &packet->packet.nmb;
@@ -469,7 +467,8 @@ struct response_record *queue_register_name( struct subnet_record *subrec,
{
struct packet_struct *p;
struct response_record *rrec;
-
+ struct sockaddr_storage ss;
+ const struct sockaddr_storage *pss = NULL;
if(assert_check_subnet(subrec))
return NULL;
@@ -478,7 +477,16 @@ struct response_record *queue_register_name( struct subnet_record *subrec,
subrec->bcast_ip)) == NULL)
return NULL;
- if(initiate_name_register_packet( p, nb_flags, iface_ip(subrec->bcast_ip)) == False) {
+ in_addr_to_sockaddr_storage(&ss, subrec->bcast_ip);
+ pss = iface_ip(&ss);
+ if (!pss || pss->ss_family != AF_INET) {
+ p->locked = False;
+ free_packet(p);
+ return NULL;
+ }
+
+ if(initiate_name_register_packet(p, nb_flags,
+ &((const struct sockaddr_in *)pss)->sin_addr) == False) {
p->locked = False;
free_packet(p);
return NULL;
@@ -698,7 +706,7 @@ struct response_record *queue_query_name( struct subnet_record *subrec,
/* queries to the WINS server turn up here as queries to IP 0.0.0.0
These need to be handled a bit differently */
- if (subrec->type == UNICAST_SUBNET && is_zero_ip(to_ip)) {
+ if (subrec->type == UNICAST_SUBNET && is_zero_ip_v4(to_ip)) {
/* What we really need to do is loop over each of our wins
* servers and wins server tags here, but that just doesn't
* fit our architecture at the moment (userdata may already
@@ -724,14 +732,14 @@ struct response_record *queue_query_name( struct subnet_record *subrec,
DEBUG(10,("queue_query_name: bind_interfaces_only is set, looking for suitable source IP\n"));
for(i = 0; i < iface_count(); i++) {
- struct in_addr *ifip = iface_n_ip(i);
+ const struct in_addr *ifip = iface_n_ip_v4(i);
- if(ifip == NULL) {
+ if (ifip == NULL) {
DEBUG(0,("queue_query_name: interface %d has NULL IP address !\n", i));
continue;
}
- if (ip_equal(*ifip,loopback_ip)) {
+ if (is_loopback_ip_v4(*ifip)) {
DEBUG(5,("queue_query_name: ignoring loopback interface (%d)\n", i));
continue;
}
@@ -869,7 +877,7 @@ void reply_netbios_packet(struct packet_struct *orig_packet,
const char *packet_type = "unknown";
/* Check if we are sending to or from ourselves. */
- if(ismyip(orig_packet->ip) && (orig_packet->port == global_nmb_port))
+ if(ismyip_v4(orig_packet->ip) && (orig_packet->port == global_nmb_port))
loopback_this_packet = True;
nmb = &packet.packet.nmb;
@@ -1020,7 +1028,7 @@ static struct subnet_record *find_subnet_for_dgram_browse_packet(struct packet_s
/* Go through all the broadcast subnets and see if the mask matches. */
for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
- if(same_net(p->ip, subrec->bcast_ip, subrec->mask_ip))
+ if(same_net_v4(p->ip, subrec->bcast_ip, subrec->mask_ip))
return subrec;
}
@@ -1176,7 +1184,7 @@ static BOOL listening(struct packet_struct *p,struct nmb_name *nbname)
struct subnet_record *subrec = NULL;
for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
- if(same_net(p->ip, subrec->bcast_ip, subrec->mask_ip))
+ if(same_net_v4(p->ip, subrec->bcast_ip, subrec->mask_ip))
break;
}
@@ -1439,7 +1447,7 @@ static struct subnet_record *find_subnet_for_nmb_packet( struct packet_struct *p
/* Go through all the broadcast subnets and see if the mask matches. */
for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) {
- if(same_net(p->ip, subrec->bcast_ip, subrec->mask_ip))
+ if(same_net_v4(p->ip, subrec->bcast_ip, subrec->mask_ip))
return subrec;
}
@@ -1814,12 +1822,12 @@ BOOL listen_for_packets(BOOL run_election)
* only is set then check it came from one of our local nets.
*/
if(lp_bind_interfaces_only() && (sock_array[i] == ClientNMB) &&
- (!is_local_net(packet->ip))) {
+ (!is_local_net_v4(packet->ip))) {
DEBUG(7,("discarding nmb packet sent to broadcast socket from %s:%d\n",
inet_ntoa(packet->ip),packet->port));
free_packet(packet);
- } else if ((ip_equal(loopback_ip, packet->ip) ||
- ismyip(packet->ip)) && packet->port == global_nmb_port &&
+ } else if ((is_loopback_ip_v4(packet->ip) ||
+ ismyip_v4(packet->ip)) && packet->port == global_nmb_port &&
packet->packet.nmb.header.nm_flags.bcast) {
DEBUG(7,("discarding own bcast packet from %s:%d\n",
inet_ntoa(packet->ip),packet->port));
@@ -1841,12 +1849,12 @@ BOOL listen_for_packets(BOOL run_election)
* only is set then check it came from one of our local nets.
*/
if(lp_bind_interfaces_only() && (sock_array[i] == ClientDGRAM) &&
- (!is_local_net(packet->ip))) {
+ (!is_local_net_v4(packet->ip))) {
DEBUG(7,("discarding dgram packet sent to broadcast socket from %s:%d\n",
inet_ntoa(packet->ip),packet->port));
free_packet(packet);
- } else if ((ip_equal(loopback_ip, packet->ip) ||
- ismyip(packet->ip)) && packet->port == DGRAM_PORT) {
+ } else if ((is_loopback_ip_v4(packet->ip) ||
+ ismyip_v4(packet->ip)) && packet->port == DGRAM_PORT) {
DEBUG(7,("discarding own dgram packet from %s:%d\n",
inet_ntoa(packet->ip),packet->port));
free_packet(packet);
@@ -1880,7 +1888,7 @@ BOOL send_mailslot(BOOL unique, const char *mailslot,char *buf, size_t len,
memset((char *)&p,'\0',sizeof(p));
- if(ismyip(dest_ip) && (dest_port == DGRAM_PORT)) /* Only if to DGRAM_PORT */
+ if(ismyip_v4(dest_ip) && (dest_port == DGRAM_PORT)) /* Only if to DGRAM_PORT */
loopback_this_packet = True;
/* generate_name_trn_id(); */ /* Not used, so gone, RJS */
diff --git a/source/nmbd/nmbd_processlogon.c b/source/nmbd/nmbd_processlogon.c
index abac2ac7764..4b5fe28d4e9 100644
--- a/source/nmbd/nmbd_processlogon.c
+++ b/source/nmbd/nmbd_processlogon.c
@@ -54,6 +54,19 @@ void process_logon_packet(struct packet_struct *p, char *buf,int len,
pstring ascuser;
char *unicomp; /* Unicode computer name. */
size_t size;
+ struct sockaddr_storage ss;
+ const struct sockaddr_storage *pss;
+ struct in_addr ip;
+
+ in_addr_to_sockaddr_storage(&ss, p->ip);
+ pss = iface_ip(&ss);
+ if (!pss) {
+ DEBUG(5,("process_logon_packet:can't find outgoing interface "
+ "for packet from IP %s\n",
+ inet_ntoa(p->ip) ));
+ return;
+ }
+ ip = ((struct sockaddr_in *)pss)->sin_addr;
memset(outbuf, 0, sizeof(outbuf));
@@ -127,7 +140,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) ));
global_myname(), 0x0,
mach_str,
dgram->source_name.name_type,
- p->ip, *iface_ip(p->ip), p->port);
+ p->ip, ip, p->port);
break;
}
@@ -258,7 +271,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n",
global_myname(), 0x0,
source_name,
dgram->source_name.name_type,
- p->ip, *iface_ip(p->ip), p->port);
+ p->ip, ip, p->port);
return;
}
@@ -543,7 +556,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n",
SIVAL(q, 0, 0x00000002);
q += 4; /* unknown */
- SIVAL(q, 0, (iface_ip(p->ip))->s_addr);
+ SIVAL(q, 0, ntohl(ip.s_addr));
q += 4;
SIVAL(q, 0, 0x00000000);
q += 4; /* unknown */
@@ -573,7 +586,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n",
global_myname(), 0x0,
source_name,
dgram->source_name.name_type,
- p->ip, *iface_ip(p->ip), p->port);
+ p->ip, ip, p->port);
break;
}
diff --git a/source/nmbd/nmbd_subnetdb.c b/source/nmbd/nmbd_subnetdb.c
index 690ca5b6218..7fd241cf624 100644
--- a/source/nmbd/nmbd_subnetdb.c
+++ b/source/nmbd/nmbd_subnetdb.c
@@ -24,7 +24,6 @@
#include "includes.h"
-extern struct in_addr loopback_ip;
extern int global_nmb_port;
/* This is the broadcast subnets database. */
@@ -169,12 +168,16 @@ static struct subnet_record *make_subnet(const char *name, enum subnet_type type
Create a normal subnet
**************************************************************************/
-struct subnet_record *make_normal_subnet(struct interface *iface)
+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(iface->ip), NORMAL_SUBNET,
- iface->ip, iface->bcast, iface->nmask);
+ subrec = make_subnet(inet_ntoa(*pip), NORMAL_SUBNET,
+ *pip, *pbcast, *pnmask);
if (subrec) {
add_subnet(subrec);
}
@@ -186,8 +189,9 @@ struct subnet_record *make_normal_subnet(struct interface *iface)
**************************************************************************/
BOOL create_subnets(void)
-{
- int num_interfaces = iface_count();
+{
+ /* We only count IPv4 interfaces whilst we're waiting. */
+ int num_interfaces = iface_count_v4();
int i;
struct in_addr unicast_ip, ipzero;
@@ -197,47 +201,59 @@ BOOL create_subnets(void)
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) {
+ /* We only count IPv4 interfaces here. */
+ while (iface_count_v4() == 0) {
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.
+ * the linked list.
*/
for (i = 0 ; i < num_interfaces; i++) {
- struct interface *iface = get_interface(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 (ip_equal(iface->ip, loopback_ip)) {
+ if (is_loopback_addr(&iface->ip)) {
DEBUG(2,("create_subnets: Ignoring loopback interface.\n" ));
continue;
}
@@ -254,8 +270,8 @@ BOOL create_subnets(void)
}
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);
+ /* Pick the first interface IPv4 address as the WINS server ip. */
+ const struct in_addr *nip = first_ipv4_iface();
if (!nip) {
return False;
@@ -266,7 +282,7 @@ BOOL create_subnets(void)
/* 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);
+ zero_ip_v4(&unicast_ip);
}
/*
@@ -279,7 +295,7 @@ BOOL create_subnets(void)
unicast_subnet = make_subnet( "UNICAST_SUBNET", UNICAST_SUBNET,
unicast_ip, unicast_ip, unicast_ip);
- zero_ip(&ipzero);
+ zero_ip_v4(&ipzero);
remote_broadcast_subnet = make_subnet( "REMOTE_BROADCAST_SUBNET",
REMOTE_BROADCAST_SUBNET,
diff --git a/source/nmbd/nmbd_synclists.c b/source/nmbd/nmbd_synclists.c
index 60d1d3fd8dc..6b716bdf355 100644
--- a/source/nmbd/nmbd_synclists.c
+++ b/source/nmbd/nmbd_synclists.c
@@ -149,7 +149,7 @@ void sync_browse_lists(struct work_record *work,
START_PROFILE(sync_browse_lists);
/* Check we're not trying to sync with ourselves. This can
happen if we are a domain *and* a local master browser. */
- if (ismyip(ip)) {
+ if (ismyip_v4(ip)) {
done:
END_PROFILE(sync_browse_lists);
return;
diff --git a/source/nmbd/nmbd_winsproxy.c b/source/nmbd/nmbd_winsproxy.c
index 2c57c4649a0..ff80c15ffff 100644
--- a/source/nmbd/nmbd_winsproxy.c
+++ b/source/nmbd/nmbd_winsproxy.c
@@ -107,7 +107,7 @@ returned for name %s.\n", nmb_namestr(nmbname) ));
if(namerec && original_packet->packet.nmb.header.nm_flags.bcast) {
for( i = 0; i < namerec->data.num_ips; i++) {
- if( same_net( namerec->data.ip[i], orig_broadcast_subnet->myip,
+ if( same_net_v4( namerec->data.ip[i], orig_broadcast_subnet->myip,
orig_broadcast_subnet->mask_ip ) ) {
DEBUG( 5, ( "wins_proxy_name_query_request_success: name %s is a WINS \
proxy name and is also on the same subnet (%s) as the requestor. \
diff --git a/source/nmbd/nmbd_winsserver.c b/source/nmbd/nmbd_winsserver.c
index cd07549b301..66c060f6527 100644
--- a/source/nmbd/nmbd_winsserver.c
+++ b/source/nmbd/nmbd_winsserver.c
@@ -1273,7 +1273,7 @@ already exists in WINS as a GROUP name.\n", nmb_namestr(question) ));
if ( namerec != NULL ) {
pull_ascii_nstring(name, sizeof(name), namerec->name.name);
if( is_myname(name) ) {
- if(!ismyip(from_ip)) {
+ if(!ismyip_v4(from_ip)) {
DEBUG(3,("wins_process_name_registration_request: Attempt to register name %s. Name \
is one of our (WINS server) names. Denying registration.\n", nmb_namestr(question) ));
send_wins_name_registration_response(RFS_ERR, 0, p);
@@ -1595,7 +1595,7 @@ already exists in WINS as a GROUP name.\n", nmb_namestr(question) ));
*/
if((namerec != NULL) && (is_myname(namerec->name.name)) ) {
- if(!ismyip(from_ip)) {
+ if(!ismyip_v4(from_ip)) {
DEBUG(3,("wins_process_multihomed_name_registration_request: Attempt to register name %s. Name \
is one of our (WINS server) names. Denying registration.\n", nmb_namestr(question) ));
send_wins_name_registration_response(RFS_ERR, 0, p);
diff --git a/source/nmbd/nmbd_workgroupdb.c b/source/nmbd/nmbd_workgroupdb.c
index 60194e99155..82c3a31669d 100644
--- a/source/nmbd/nmbd_workgroupdb.c
+++ b/source/nmbd/nmbd_workgroupdb.c
@@ -110,7 +110,7 @@ static struct work_record *create_workgroup(const char *name, int ttl)
/* No known domain master browser as yet. */
*work->dmb_name.name = '\0';
- zero_ip(&work->dmb_addr);
+ zero_ip_v4(&work->dmb_addr);
/* WfWg uses 01040b01 */
/* Win95 uses 01041501 */