Esempio n. 1
0
File: gdbudp.c Progetto: 3a9LL/panda
struct gdb_transport *gdbudp_configure ( const char *name, struct sockaddr_in *addr ) {
	struct settings *settings;

	/* Release old network device */
	netdev_put ( netdev );

	netdev = find_netdev ( name );
	if ( !netdev ) {
		return NULL;
	}

	/* Hold network device */
	netdev_get ( netdev );

	/* Source UDP port */
	source_addr.sin_port = ( addr && addr->sin_port ) ? addr->sin_port : htons ( DEFAULT_PORT );

	/* Source IP address */
	if ( addr && addr->sin_addr.s_addr ) {
		source_addr.sin_addr.s_addr = addr->sin_addr.s_addr;
	} else {
		settings = netdev_settings ( netdev );
		fetch_ipv4_setting ( settings, &ip_setting, &source_addr.sin_addr );
		if ( source_addr.sin_addr.s_addr == 0 ) {
			netdev_put ( netdev );
			netdev = NULL;
			return NULL;
		}
	}

	return &udp_gdb_transport;
}
Esempio n. 2
0
/**
 * Fill in NIC portion of iBFT
 *
 * @v nic		NIC portion of iBFT
 * @v strings		iBFT string block descriptor
 * @v netdev		Network device
 * @ret rc		Return status code
 */
static int ibft_fill_nic ( struct ibft_nic *nic,
			   struct ibft_string_block *strings,
			   struct net_device *netdev ) {
	struct ll_protocol *ll_protocol = netdev->ll_protocol;
	struct in_addr netmask_addr = { 0 };
	unsigned int netmask_count = 0;
	int rc;

	/* Extract values from DHCP configuration */
	ibft_set_ipaddr_option ( &nic->ip_address, &ip_setting );
	DBG ( "iBFT NIC IP = %s\n", ibft_ipaddr ( &nic->ip_address ) );
	ibft_set_ipaddr_option ( &nic->gateway, &gateway_setting );
	DBG ( "iBFT NIC gateway = %s\n", ibft_ipaddr ( &nic->gateway ) );
	ibft_set_ipaddr_option ( &nic->dns[0], &dns_setting );
	DBG ( "iBFT NIC DNS = %s\n", ibft_ipaddr ( &nic->dns[0] ) );
	if ( ( rc = ibft_set_string_option ( strings, &nic->hostname,
					     &hostname_setting ) ) != 0 )
		return rc;
	DBG ( "iBFT NIC hostname = %s\n",
	      ibft_string ( strings, &nic->hostname ) );

	/* Derive subnet mask prefix from subnet mask */
	fetch_ipv4_setting ( NULL, &netmask_setting, &netmask_addr );
	while ( netmask_addr.s_addr ) {
		if ( netmask_addr.s_addr & 0x1 )
			netmask_count++;
		netmask_addr.s_addr >>= 1;
	}
	nic->subnet_mask_prefix = netmask_count;
	DBG ( "iBFT NIC subnet = /%d\n", nic->subnet_mask_prefix );

	/* Extract values from net-device configuration */
	if ( ( rc = ll_protocol->eth_addr ( netdev->ll_addr,
					    nic->mac_address ) ) != 0 ) {
		DBG ( "Could not determine iBFT MAC: %s\n", strerror ( rc ) );
		return rc;
	}
	DBG ( "iBFT NIC MAC = %s\n", eth_ntoa ( nic->mac_address ) );
	nic->pci_bus_dev_func = netdev->dev->desc.location;
	DBG ( "iBFT NIC PCI = %04x\n", nic->pci_bus_dev_func );

	return 0;
}
Esempio n. 3
0
/**
 * Apply DNS settings
 *
 * @ret rc		Return status code
 */
static int apply_dns_settings ( void ) {
	struct sockaddr_in *sin_nameserver =
		( struct sockaddr_in * ) &nameserver;
	int len;

	if ( ( len = fetch_ipv4_setting ( NULL, &dns_setting,
					  &sin_nameserver->sin_addr ) ) >= 0 ){
		sin_nameserver->sin_family = AF_INET;
		DBG ( "DNS using nameserver %s\n",
		      inet_ntoa ( sin_nameserver->sin_addr ) );
	}

	/* Get local domain DHCP option */
	if ( ( len = fetch_string_setting_copy ( NULL, &domain_setting,
						 &localdomain ) ) >= 0 )
		DBG ( "DNS local domain %s\n", localdomain );

	return 0;
}
Esempio n. 4
0
/**
 * Apply syslog settings
 *
 * @ret rc		Return status code
 */
static int apply_syslog_settings ( void ) {
	struct sockaddr_in *sin_logserver =
		( struct sockaddr_in * ) &logserver;
	struct in_addr old_addr;
	int len;
	int rc;

	/* Fetch log server */
	syslog_console.disabled = 1;
	old_addr.s_addr = sin_logserver->sin_addr.s_addr;
	if ( ( len = fetch_ipv4_setting ( NULL, &syslog_setting,
					  &sin_logserver->sin_addr ) ) >= 0 ) {
		syslog_console.disabled = 0;
	}

	/* Do nothing unless log server has changed */
	if ( sin_logserver->sin_addr.s_addr == old_addr.s_addr )
		return 0;

	/* Reset syslog connection */
	intf_restart ( &syslogger, 0 );

	/* Do nothing unless we have a log server */
	if ( syslog_console.disabled ) {
		DBG ( "SYSLOG has no log server\n" );
		return 0;
	}

	/* Connect to log server */
	if ( ( rc = xfer_open_socket ( &syslogger, SOCK_DGRAM,
				       ( ( struct sockaddr * ) &logserver ),
				       NULL ) ) != 0 ) {
		DBG ( "SYSLOG cannot connect to log server: %s\n",
		      strerror ( rc ) );
		return rc;
	}
	DBG ( "SYSLOG using log server %s\n",
	      inet_ntoa ( sin_logserver->sin_addr ) );

	return 0;
}
Esempio n. 5
0
/**
 * Fill in an IP address within iBFT from configuration setting
 *
 * @v ipaddr		IP address field
 * @v setting		Configuration setting
 * @v tag		DHCP option tag
 */
static void ibft_set_ipaddr_option ( struct ibft_ipaddr *ipaddr,
				     struct setting *setting ) {
	struct in_addr in = { 0 };
	fetch_ipv4_setting ( NULL, setting, &in );
	ibft_set_ipaddr ( ipaddr, in );
}