Ejemplo n.º 1
0
int br_set_port_prio(const char *bridge, char *port, char *prio)
{
	if (!ifexists(bridge))
		return -1;
	return port_set(bridge, port, "priority", atoi(prio),
			BRCTL_SET_PORT_PRIORITY);
}
Ejemplo n.º 2
0
void write_port(uint8_t chan, uint8_t *buf, uint8_t len)
{
	uint8_t a,b;
	port_t *portp = &ports[chan-1];
	_P_VARS(portp)

	a = *buf++;
	if(len == 1) // len=1: set value
		port_set(portp,a);
	else {
		b = *buf++;
		flg = (portp->flags&~b) | (a&b);
		portp->flags = flg;
		if(b&PFLG_CURRENT)
			port_set(portp,a&0x80);
		else if (b&3)
			port_set_out(portp,flg&3);
	}
}
Ejemplo n.º 3
0
int mcast_send_packet( const char msg[], IP *src_addr, const char ifname[] ) {
	char addrbuf[FULL_ADDSTRLEN+1];
	int sock;
	IP addr;

	/* Copy address to separate field and set port */
	memcpy( &addr, src_addr, addr_len( (IP*) src_addr ) );
	port_set( &addr, addr_port(&g_lpd_addr) );

	/* For IPv6, only send from link local addresses */
	if( addr.ss_family == AF_INET6) {
		unsigned char* a = &((IP6*) &addr)->sin6_addr.s6_addr[0];
		if( !(a[0] == 0xFE && a[1] == 0x80) ) {
			return 1;
		}
	}

	if( (sock = socket( gconf->af, SOCK_DGRAM, IPPROTO_UDP )) < 0 ) {
		log_warn( "LPD: Cannot create send socket: %s", strerror( errno ) );
		goto skip;
	}

	const int opt_on = 1;
	if( setsockopt( sock, SOL_SOCKET, SO_REUSEADDR, &opt_on, sizeof(opt_on) ) < 0 ) {
		log_warn( "LPD: Unable to set SO_REUSEADDR: %s", strerror( errno ) );
		goto skip;
	}

	if( bind( sock, (struct sockaddr*) &addr, addr_len( &addr ) ) < 0 ) {
		log_warn( "LPD: Cannot bind send socket: %s", strerror( errno ) );
		goto skip;
	}

	if( sendto( sock, msg, strlen( msg ), 0, (struct sockaddr*) &g_lpd_addr, addr_len( &g_lpd_addr ) ) < 0 ) {
		log_warn( "LPD: Cannot send message from '%s': %s", str_addr( &addr, addrbuf ), strerror( errno ) );
		goto skip;
	}

	log_debug( "LPD: Send peer discovery packet from source address: %s", str_addr( src_addr, addrbuf ) );

	skip:
	close(sock);

	return 0;
}
Ejemplo n.º 4
0
int br_set_path_cost(const char *bridge, const char *port, int cost)
{
	return port_set(bridge, port, "path_cost", cost, BRCTL_SET_PATH_COST);
}
Ejemplo n.º 5
0
int br_set_port_priority(const char *bridge, const char *port, int priority)
{
	return port_set(bridge, port, "priority", priority, BRCTL_SET_PORT_PRIORITY);
}
Ejemplo n.º 6
0
void handle_mcast( int rc, int sock_recv ) {
	char addrbuf[FULL_ADDSTRLEN+1];
	char buf[512];
	IP c_addr;
	socklen_t addrlen;
	int rc_recv;

	if( g_mcast_time <= time_now_sec() ) {
		if( kad_count_nodes( 0 ) == 0 ) {
			/* Join multicast group if possible */
			if( g_mcast_registered == 0 && multicast_set_groups( sock_recv, &g_lpd_addr, gconf->dht_ifname, 1 ) == 0 ) {
				log_info( "LPD: No peers known. Joined multicast group." );
				g_mcast_registered = 1;
			}

			if( g_mcast_registered == 1 ) {
				log_info( "LPD: Send multicast message to find nodes." );

				/* Create message */
				snprintf(
					buf, sizeof(buf),
					msg_fmt, str_addr( &g_lpd_addr, addrbuf ),
					atoi( gconf->dht_port ), g_infohash
				);

				mcast_send_packets( buf, gconf->dht_ifname );
			}
		}

		/* Cap number of received packets to 10 per minute */
		g_packet_limit = 5 * PACKET_LIMIT_MAX;

		/* Try again in ~5 minutes */
		g_mcast_time = time_add_min( 5 );
	}

	if( rc <= 0 ) {
		return;
	}

	/* Reveice multicast ping */
	addrlen = sizeof(IP);
	rc_recv = recvfrom( sock_recv, buf, sizeof(buf), 0, (struct sockaddr*) &c_addr, (socklen_t*) &addrlen );
	if( rc_recv < 0 ) {
		log_warn( "LPD: Cannot receive multicast message: %s", strerror( errno ) );
		return;
	}

	if( g_packet_limit < 0 ) {
		/* Too much traffic - leave multicast group for now */
		if( g_mcast_registered == 1 && multicast_set_groups( sock_recv, &g_lpd_addr, gconf->dht_ifname, 0 ) == 0 ) {
			log_warn( "LPD: Too much traffic. Left multicast group." );
			g_mcast_registered = 0;
		}
		return;
	} else {
		g_packet_limit--;
	}

	if( rc_recv >= sizeof(buf) ) {
		return;
	} else {
		buf[rc_recv] = '\0';
	}

	int port = parse_packet( buf );
	if( port > 0 ) {
		port_set( &c_addr, port );
		log_debug( "LPD: Ping lonely peer at %s", str_addr( &c_addr, addrbuf ) );
		kad_ping( &c_addr );
	} else {
		log_debug( "LPD: Received invalid packet on multicast group." );
	}
}
Ejemplo n.º 7
0
int br_set_hairpin_mode(const char *bridge, const char *port, int hairpin_mode)
{
	return port_set(bridge, port, "hairpin_mode", hairpin_mode, 0);
}