Skip to content

Commit

Permalink
*** empty log message ***
Browse files Browse the repository at this point in the history
  • Loading branch information
massie committed Feb 3, 2005
1 parent 5603720 commit 5d3549c
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 33 deletions.
4 changes: 4 additions & 0 deletions Makefile.am
Expand Up @@ -46,6 +46,9 @@ dist-local: README ganglia.html ChangeLog
# We handle distributing the ./srclib directory here
# since the packages in that directory might not
# handle a "make dist" correctly
#
# We also go through and make sure all the files have
# the same timestamp with the last command here...
dist-hook:
for subdir in "./srclib ./web"; do \
tar -c --exclude=".libs" --exclude "core.*" --exclude="*CVS" \
Expand All @@ -54,5 +57,6 @@ dist-hook:
--exclude="*.tar.gz" \
-f - $$subdir | (cd $(distdir) && tar -xf -)\
done;
find $(distir) -exec touch -r $(distdir)/Makefile.am {} \;

bin_SCRIPTS = ganglia-config
2 changes: 2 additions & 0 deletions bootstrap
@@ -1,5 +1,7 @@
#!/bin/sh
# $Id$
echo "Setting timestamps"
find . -exec touch -r Makefile.am {} \;
echo "Bootstrapping libmetrics"
cd srclib/libmetrics && ./bootstrap
cd ../..
Expand Down
48 changes: 42 additions & 6 deletions gmond/conf.pod
Expand Up @@ -162,9 +162,10 @@ You can specify as many B<udp_recv_channel> sections as you like within the
limits of memory and file descriptors. If B<gmond> is configured B<deaf>
this attribute will be ignored.

The B<udp_recv_channel> section has a total of seven attributes:
B<mcast_join>, B<bind>, B<port>, B<mcast_if>, B<allow_ip>
and B<allow_mask>.
The B<udp_recv_channel> section has following attributes:
B<mcast_join>, B<bind>, B<port>, B<mcast_if>, B<family>. The
B<udp_recv_channel> can also have an B<acl> definition (see
ACCESS CONTROL LISTS below).

For example, the 2.5.x gmond ran with a single udp receive channel...

Expand All @@ -182,7 +183,24 @@ on the specified B<port>.

You can use the B<bind> attribute to bind to a particular local address.

Note: for multicast, specifying a B<bind> address that equals the B<mcast_join>
The family address is set to B<inet4> by default. If you want to bind
the port to an B<inet6> port, you need to specify that in the family
attribute. Ganglia will not allow IPV6=>IPV4 mapping (for portability
and security reasons). If you want to listen on both B<inet4> and
B<inet6> for a particular port, explicitly state it with the following:

udp_recv_channel {
port = 8666
family = inet4
}
udp_recv_channel {
port = 8666
family = inet6
}

If you specify a bind address, the family of that address takes precedence.

Multicast Note: for multicast, specifying a B<bind> address that equals the B<mcast_join>
address will prevent unicast UDP messages to the same B<port> from being
processed.

Expand All @@ -192,8 +210,9 @@ You can specify as many B<tcp_accept_channel> sections as you like
within the limitations of memory and file descriptors. If B<gmond>
is configured to be B<mute>, then these sections are ignored.

The B<tcp_accept_channel> has six attributes: B<bind>, B<port>,
B<interface>, B<allow_ip> and B<allow_mask>.
The B<tcp_accept_channel> has the following attributes: B<bind>, B<port>,
B<interface>, and B<family>. A B<tcp_accept_channel> may also have
an B<acl> section specified (see ACCESS CONTROL LISTS below).

For example, 2.5.x gmond would accept connections on a single TCP
channel.
Expand All @@ -208,6 +227,23 @@ local address B<gmond> will bind to for this channel.
The B<port> is an integer than specifies which port to answer
requests for data.

The B<family> address is set to B<inet4> by default. If you want to bind
the port to an B<inet6> port, you need to specify that in the family
attribute. Ganglia will not allow IPV6=>IPV4 mapping (for portability
and security reasons). If you want to listen on both B<inet4> and
B<inet6> for a particular port, explicitly state it with the following:

udp_recv_channel {
port = 8666
family = inet4
}
udp_recv_channel {
port = 8666
family = inet6
}

If you specify a bind address, the family of that address takes precedence.

The B<interface> is not implemented at this time (use B<bind>).

=head2 collection_group
Expand Down
45 changes: 38 additions & 7 deletions gmond/gmond.c
Expand Up @@ -386,6 +386,29 @@ Ganglia_acl_action( Ganglia_acl *acl, apr_sockaddr_t *addr )
return acl->default_action;
}

static int32_t
get_sock_family( char *family )
{
if( strchr( family, '4' ))
{
return APR_INET;
}
else if( strchr( family, '6'))
{
#if APR_INET6
return APR_INET6;
#else
fprintf(stderr,"IPv6 is not supported on this host. Exiting.\n");
exit(1);
#endif
}

fprintf(stderr,"Unknown family '%s'. Try inet4|inet6. Exiting.\n", family);
exit(1);
/* shouldn't get here */
return APR_UNSPEC;
}

static void
setup_listen_channels_pollset( void )
{
Expand All @@ -403,17 +426,19 @@ setup_listen_channels_pollset( void )
for(i = 0; i< num_udp_recv_channels; i++)
{
cfg_t *udp_recv_channel;
char *mcast_join, *mcast_if, *bindaddr;
char *mcast_join, *mcast_if, *bindaddr, *family;
int port;
apr_socket_t *socket = NULL;
apr_pollfd_t socket_pollfd;
apr_pool_t *pool = NULL;
int32_t sock_family = APR_INET;

udp_recv_channel = cfg_getnsec( config_file, "udp_recv_channel", i);
mcast_join = cfg_getstr( udp_recv_channel, "mcast_join" );
mcast_if = cfg_getstr( udp_recv_channel, "mcast_if" );
port = cfg_getint( udp_recv_channel, "port");
bindaddr = cfg_getstr( udp_recv_channel, "bind");
family = cfg_getstr( udp_recv_channel, "family");

debug_msg("udp_recv_channel mcast_join=%s mcast_if=%s port=%d bind=%s",
mcast_join? mcast_join:"NULL",
Expand All @@ -423,21 +448,23 @@ setup_listen_channels_pollset( void )
/* Create a sub-pool for this channel */
apr_pool_create(&pool, global_context);

sock_family = get_sock_family(family);

if( mcast_join )
{
/* Listen on the specified multicast channel */
socket = create_mcast_server(pool, mcast_join, port, bindaddr, mcast_if );
socket = create_mcast_server(pool, sock_family, mcast_join, port, bindaddr, mcast_if );
if(!socket)
{
fprintf(stderr,"Error creating multicast server mcast_join=%s port=%d mcast_if=%s. Exiting.\n",
mcast_join? mcast_join: "NULL", port, mcast_if? mcast_if:"NULL");
fprintf(stderr,"Error creating multicast server mcast_join=%s port=%d mcast_if=%s family='%s'. Exiting.\n",
mcast_join? mcast_join: "NULL", port, mcast_if? mcast_if:"NULL",family);
exit(1);
}
}
else
{
/* Create a UDP server */
socket = create_udp_server( pool, port, bindaddr );
socket = create_udp_server( pool, sock_family, port, bindaddr );
if(!socket)
{
fprintf(stderr,"Error creating UDP server on port %d bind=%s. Exiting.\n",
Expand Down Expand Up @@ -484,25 +511,29 @@ setup_listen_channels_pollset( void )
for(i=0; i< num_tcp_accept_channels; i++)
{
cfg_t *tcp_accept_channel = cfg_getnsec( config_file, "tcp_accept_channel", i);
char *bindaddr, *interface;
char *bindaddr, *interface, *family;
int port, timeout;
apr_socket_t *socket = NULL;
apr_pollfd_t socket_pollfd;
apr_pool_t *pool = NULL;
int32_t sock_family;

port = cfg_getint( tcp_accept_channel, "port");
bindaddr = cfg_getstr( tcp_accept_channel, "bind");
interface = cfg_getstr( tcp_accept_channel, "interface");
timeout = cfg_getint( tcp_accept_channel, "timeout");
family = cfg_getstr( tcp_accept_channel, "family");

debug_msg("tcp_accept_channel bind=%s port=%d",
bindaddr? bindaddr: "NULL", port);

/* Create a subpool context */
apr_pool_create(&pool, global_context);

sock_family = get_sock_family(family);

/* Create the socket for the channel */
socket = create_tcp_server(pool, port, bindaddr, interface);
socket = create_tcp_server(pool, sock_family, port, bindaddr, interface);
if(!socket)
{
fprintf(stderr,"Unable to create tcp_accept_channel. Exiting.\n");
Expand Down
48 changes: 34 additions & 14 deletions lib/apr_net.c
@@ -1,3 +1,7 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdio.h>
#include <stdlib.h>
#include <apr_strings.h>
Expand Down Expand Up @@ -90,16 +94,20 @@ create_udp_client(apr_pool_t *context, char *host, apr_port_t port)
}

static apr_socket_t *
create_net_server(apr_pool_t *context, int type, apr_port_t port, char *bind)
create_net_server(apr_pool_t *context, int32_t ofamily, int type, apr_port_t port, char *bind_addr)
{
apr_sockaddr_t *localsa = NULL;
apr_socket_t *sock = NULL;
apr_status_t stat;
int family = APR_UNSPEC;
int32_t family = ofamily;

if(bind)
/* We set family to the family specified in the option. If however a bind address
* is also specified, it's family will take precedence.
* e.g. ofamily = APR_INET6 but the bind address is "127.0.0.1" which is IPv4
* the family will be set to the bind address family */
if(bind_addr)
{
stat = apr_sockaddr_info_get(&localsa, bind, APR_UNSPEC, port, 0, context);
stat = apr_sockaddr_info_get(&localsa, bind_addr, APR_UNSPEC, port, 0, context);
if (stat != APR_SUCCESS)
return NULL;

Expand Down Expand Up @@ -131,34 +139,45 @@ create_net_server(apr_pool_t *context, int type, apr_port_t port, char *bind)
apr_sockaddr_port_set(localsa, port);
}

#if APR_HAVE_IPV6
if (localsa->family == APR_INET6)
{
int one = 1;
/* Don't accept IPv4 connections on an IPv6 listening socket */
stat = apr_socket_opt_set(sock, APR_IPV6_V6ONLY, one);
if (stat != APR_SUCCESS && stat != APR_ENOTIMPL)
{
apr_socket_close(sock);
return NULL;
}
}
#endif

stat = apr_bind(sock, localsa);
if( stat != APR_SUCCESS)
{
apr_socket_close(sock);
/*
fprintf(stderr, "Could not bind: %s\n", apr_strerror(stat, buf, sizeof buf));
*/
return NULL;
}

return sock;
}

apr_socket_t *
create_udp_server(apr_pool_t *context, apr_port_t port, char *bind)
create_udp_server(apr_pool_t *context, int32_t family, apr_port_t port, char *bind_addr)
{
return create_net_server(context, SOCK_DGRAM, port, bind);
return create_net_server(context, family, SOCK_DGRAM, port, bind_addr);
}

apr_socket_t *
create_tcp_server(apr_pool_t *context, apr_port_t port, char *bind, char *interface)
create_tcp_server(apr_pool_t *context, int32_t family, apr_port_t port, char *bind_addr, char *interface)
{
apr_socket_t *sock = create_net_server(context, SOCK_STREAM, port, bind);
apr_socket_t *sock = create_net_server(context, family, SOCK_STREAM, port, bind_addr);
if(!sock)
{
return NULL;
}
if(apr_listen(sock,5) != APR_SUCCESS)
if(apr_listen(sock, 5) != APR_SUCCESS)
{
return NULL;
}
Expand Down Expand Up @@ -292,19 +311,20 @@ create_mcast_client(apr_pool_t *context, char *mcast_ip, apr_port_t port, int tt
{
return NULL;
}
mcast_set_ttl(socket, ttl);
return socket;
}

apr_socket_t *
create_mcast_server(apr_pool_t *context, char *mcast_ip, apr_port_t port, char *bind, char *interface)
create_mcast_server(apr_pool_t *context, int32_t family, char *mcast_ip, apr_port_t port, char *bind_addr, char *interface)
{
apr_status_t status = APR_SUCCESS;
/* NOTE: If bind is set to mcast_ip in the configuration file, then we will bind the
* the multicast address to the socket as well as the port and prevent any
* datagrams that might be delivered to this port from being processed. Otherwise,
* packets destined to the same port (but a different multicast/unicast channel) will be
* processed. */
apr_socket_t *socket = create_udp_server(context, port, bind);
apr_socket_t *socket = create_udp_server(context, family, port, bind_addr);
if(!socket)
{
return NULL;
Expand Down
6 changes: 3 additions & 3 deletions lib/apr_net.h
Expand Up @@ -8,7 +8,7 @@ apr_socket_t *
create_udp_client(apr_pool_t *context, char *ipaddr, apr_port_t port);

apr_socket_t *
create_udp_server(apr_pool_t *context, apr_port_t port, char *bind);
create_udp_server(apr_pool_t *context, int32_t family, apr_port_t port, char *bind);

APR_DECLARE(apr_status_t)
apr_sockaddr_ip_buffer_get(char *addr, int len, apr_sockaddr_t *sockaddr);
Expand All @@ -19,10 +19,10 @@ create_mcast_client(apr_pool_t *context, char *mcast_ip, apr_port_t port, int tt
int mcast_set_ttl(apr_socket_t *socket, int val);

apr_socket_t *
create_mcast_server(apr_pool_t *context, char *mcast_ip, apr_port_t port, char *bind, char *interface);
create_mcast_server(apr_pool_t *context, int32_t family, char *mcast_ip, apr_port_t port, char *bind, char *interface);

apr_socket_t *
create_tcp_server(apr_pool_t *context, apr_port_t port, char *bind, char *interface);
create_tcp_server(apr_pool_t *context, int32_t family, apr_port_t port, char *bind, char *interface);



Expand Down
6 changes: 3 additions & 3 deletions lib/libgmond.c
Expand Up @@ -79,6 +79,7 @@ static cfg_opt_t udp_recv_channel_opts[] = {
CFG_INT("port", -1, CFGF_NONE ),
CFG_STR("mcast_if", NULL, CFGF_NONE),
CFG_SEC("acl", acl_opts, CFGF_NONE),
CFG_STR("family", "inet4", CFGF_NONE),
CFG_END()
};

Expand All @@ -88,6 +89,7 @@ static cfg_opt_t tcp_accept_channel_opts[] = {
CFG_STR("interface", NULL, CFGF_NONE),
CFG_SEC("acl", acl_opts, CFGF_NONE),
CFG_INT("timeout", 0, CFGF_NONE),
CFG_STR("family", "inet4", CFGF_NONE),
CFG_END()
};

Expand Down Expand Up @@ -574,15 +576,13 @@ Ganglia_udp_send_channels_create( Ganglia_pool context, Ganglia_gmond_config con
if( mcast_join )
{
/* We'll be listening on a multicast channel */
socket = create_mcast_client(pool, mcast_join, port, 0);
socket = create_mcast_client(pool, mcast_join, port, ttl);
if(!socket)
{
fprintf(stderr,"Unable to join multicast channel %s:%d. Exiting\n",
mcast_join, port);
exit(1);
}

mcast_set_ttl(socket, ttl);
}
else
{
Expand Down

0 comments on commit 5d3549c

Please sign in to comment.