Exemplo n.º 1
0
/*
Looks up a previously stored state, or generates a new one. No assumptions are
made about whether the board state is in reduced form already. Never fails. If
the memory is full it allocates a new state regardless. If the state is found
and returned it's OpenMP lock is first set. Thread-safe.
RETURNS the state information
*/
tt_stats * tt_lookup_create(
    const board * b,
    bool is_black,
    u64 hash
){
    u32 key = (u32)(hash % ((u64)number_of_buckets));
    omp_lock_t * bucket_lock = is_black ? &b_table_lock : &w_table_lock;
    omp_set_lock(bucket_lock);

    tt_stats * ret = find_state(hash, b, is_black);
    if(ret == NULL) /* doesnt exist */
    {
        if(states_in_use >= max_allocated_states)
        {
            /*
            It is possible in theory for a complex ko to produce a situation
            where freeing the game tree that is not reachable doesn't free any
            states.
            */
            tt_log_status();
            char * s = alloc();
            board_to_string(s, b->p, b->last_played, b->last_eaten);
            flog_warn("tt", s);
            release(s);
            flog_warn("tt", "memory exceeded on root lookup");
        }

        ret = create_state(hash);
        memcpy(ret->p, b->p, TOTAL_BOARD_SIZ);
        ret->last_eaten_passed =
            (b->last_played == PASS) ? PASS : b->last_eaten;
        omp_set_lock(&ret->lock);

        if(is_black)
        {
            ret->next = b_stats_table[key];
            b_stats_table[key] = ret;
        }
        else
        {
            ret->next = w_stats_table[key];
            w_stats_table[key] = ret;
        }
        omp_unset_lock(bucket_lock);
    }
    else /* update */
    {
        omp_set_lock(&ret->lock);
        omp_unset_lock(bucket_lock);
    }

    return ret;
}
Exemplo n.º 2
0
/*
 * Set MD5 key for the socket, for the given IPv4 peer address.
 * If the password is NULL or zero-length, the option will be disabled.
 */
static int bgp_md5_set_socket(int socket, union sockunion *su,
			      uint16_t prefixlen, const char *password)
{
	int ret = -1;
	int en = ENOSYS;
#if HAVE_DECL_TCP_MD5SIG
	union sockunion su2;
#endif /* HAVE_TCP_MD5SIG */

	assert(socket >= 0);

#if HAVE_DECL_TCP_MD5SIG
	/* Ensure there is no extraneous port information. */
	memcpy(&su2, su, sizeof(union sockunion));
	if (su2.sa.sa_family == AF_INET)
		su2.sin.sin_port = 0;
	else
		su2.sin6.sin6_port = 0;

	/* For addresses, use the non-extended signature functionality */
	if ((su2.sa.sa_family == AF_INET && prefixlen == IPV4_MAX_PREFIXLEN)
	    || (su2.sa.sa_family == AF_INET6
		&& prefixlen == IPV6_MAX_PREFIXLEN))
		ret = sockopt_tcp_signature(socket, &su2, password);
	else
		ret = sockopt_tcp_signature_ext(socket, &su2, prefixlen,
						password);
	en = errno;
#endif /* HAVE_TCP_MD5SIG */

	if (ret < 0) {
		char sabuf[SU_ADDRSTRLEN];
		sockunion2str(su, sabuf, sizeof(sabuf));

		switch (ret) {
		case -2:
			flog_warn(
				EC_BGP_NO_TCP_MD5,
				"Unable to set TCP MD5 option on socket for peer %s (sock=%d): This platform does not support MD5 auth for prefixes",
				sabuf, socket);
			break;
		default:
			flog_warn(
				EC_BGP_NO_TCP_MD5,
				"Unable to set TCP MD5 option on socket for peer %s (sock=%d): %s",
				sabuf, socket, safe_strerror(en));
		}
	}

	return ret;
}
Exemplo n.º 3
0
Arquivo: gtp.c Projeto: gonmf/matilda
static void gtp_clear_board(
    FILE * fp,
    int id
){
    gtp_answer(fp, id, NULL);

    if(save_all_games_to_file && current_game.turns > 0)
    {
        update_player_names();
        char * filename = alloc();
        if(export_game_as_sgf_auto_named(&current_game, filename))
        {
            char * buf = alloc();
            snprintf(buf, MAX_PAGE_SIZ, "game record exported to %s", filename);
            flog_info("gtp", buf);
            release(buf);
        }
        else
            flog_warn("gtp", "failed to export game record to file");
        release(filename);
    }

    has_genmoved_as_black = false;
    has_genmoved_as_white = false;
    if(current_game.turns > 0)
        new_match_maintenance();
    clear_game_record(&current_game);
    reset_clock(&current_clock_black);
    reset_clock(&current_clock_white);
    out_on_time_warning = false;
}
Exemplo n.º 4
0
static int if_unset_prefix6_ctx(const struct zebra_dplane_ctx *ctx)
{
	char addrbuf[PREFIX_STRLEN];

	prefix2str(dplane_ctx_get_intf_addr(ctx), addrbuf, sizeof(addrbuf));

	flog_warn(EC_LIB_DEVELOPMENT, "Can't delete %s on interface %s",
		  addrbuf, dplane_ctx_get_ifname(ctx));

	return 0;
}
Exemplo n.º 5
0
Arquivo: gtp.c Projeto: gonmf/matilda
static void close_if_sentinel_found()
{
    if(sentinel_file == NULL)
        return;

    if(access(sentinel_file, F_OK) != 0)
        return;

    unlink(sentinel_file);
    flog_warn("gtp", "sentinel file found; closing");
    exit(EXIT_SUCCESS);
}
Exemplo n.º 6
0
/*
Mostly for debugging -- log the current memory status of the transpositions
table to stderr and log file.
*/
void tt_log_status()
{
    char * buf = alloc();
    u32 idx = snprintf(buf, MAX_PAGE_SIZ,
        "\n*** Transpositions table trace start ***\n\n");
    idx += snprintf(buf + idx, MAX_PAGE_SIZ - idx, "Max size in MiB: %" PRIu64
        "\n", max_size_in_mbs);
    idx += snprintf(buf + idx, MAX_PAGE_SIZ - idx, "Max allocated states: %u\n",
        max_allocated_states);
    idx += snprintf(buf + idx, MAX_PAGE_SIZ - idx, "Allocated states: %u\n",
        allocated_states);
    idx += snprintf(buf + idx, MAX_PAGE_SIZ - idx, "States in use: %u\n",
        states_in_use);
    idx += snprintf(buf + idx, MAX_PAGE_SIZ - idx, "Number of buckets: %u\n",
        number_of_buckets);
    snprintf(buf + idx, MAX_PAGE_SIZ - idx, "Maintenance mark: %u\n",
        maintenance_mark);

    flog_warn("tt", buf);
    release(buf);
}
Exemplo n.º 7
0
/*
 * Handle netlink notification informing a rule add or delete.
 * Handling of an ADD is TBD.
 * DELs are notified up, if other attributes indicate it may be a
 * notification of interest. The expectation is that if this corresponds
 * to a PBR rule added by FRR, it will be readded.
 */
int netlink_rule_change(struct nlmsghdr *h, ns_id_t ns_id, int startup)
{
	struct zebra_ns *zns;
	struct fib_rule_hdr *frh;
	struct rtattr *tb[FRA_MAX + 1];
	int len;
	char *ifname;
	struct zebra_pbr_rule rule = {};
	char buf1[PREFIX_STRLEN];
	char buf2[PREFIX_STRLEN];

	/* Basic validation followed by extracting attributes. */
	if (h->nlmsg_type != RTM_NEWRULE && h->nlmsg_type != RTM_DELRULE)
		return 0;

	/* TBD */
	if (h->nlmsg_type == RTM_NEWRULE)
		return 0;

	len = h->nlmsg_len - NLMSG_LENGTH(sizeof(struct fib_rule_hdr));
	if (len < 0) {
		zlog_err("%s: Message received from netlink is of a broken size: %d %zu",
			 __PRETTY_FUNCTION__, h->nlmsg_len,
			 (size_t)NLMSG_LENGTH(sizeof(struct fib_rule_hdr)));
		return -1;
	}

	frh = NLMSG_DATA(h);
	if (frh->family != AF_INET && frh->family != AF_INET6) {
		flog_warn(
			EC_ZEBRA_NETLINK_INVALID_AF,
			"Invalid address family: %u received from kernel rule change: %u",
			frh->family, h->nlmsg_type);
		return 0;
	}
	if (frh->action != FR_ACT_TO_TBL)
		return 0;

	memset(tb, 0, sizeof(tb));
	netlink_parse_rtattr(tb, FRA_MAX, RTM_RTA(frh), len);

	/* TBD: We don't care about rules not specifying an IIF. */
	if (tb[FRA_IFNAME] == NULL)
		return 0;

	/* If we don't know the interface, we don't care. */
	ifname = (char *)RTA_DATA(tb[FRA_IFNAME]);
	zns = zebra_ns_lookup(ns_id);
	rule.ifp = if_lookup_by_name_per_ns(zns, ifname);
	if (!rule.ifp)
		return 0;

	if (tb[FRA_PRIORITY])
		rule.rule.priority = *(uint32_t *)RTA_DATA(tb[FRA_PRIORITY]);

	if (tb[FRA_SRC]) {
		if (frh->family == AF_INET)
			memcpy(&rule.rule.filter.src_ip.u.prefix4,
			       RTA_DATA(tb[FRA_SRC]), 4);
		else
			memcpy(&rule.rule.filter.src_ip.u.prefix6,
			       RTA_DATA(tb[FRA_SRC]), 16);
		rule.rule.filter.src_ip.prefixlen = frh->src_len;
		rule.rule.filter.filter_bm |= PBR_FILTER_SRC_IP;
	}

	if (tb[FRA_DST]) {
		if (frh->family == AF_INET)
			memcpy(&rule.rule.filter.dst_ip.u.prefix4,
			       RTA_DATA(tb[FRA_DST]), 4);
		else
			memcpy(&rule.rule.filter.dst_ip.u.prefix6,
			       RTA_DATA(tb[FRA_DST]), 16);
		rule.rule.filter.dst_ip.prefixlen = frh->dst_len;
		rule.rule.filter.filter_bm |= PBR_FILTER_DST_IP;
	}

	if (tb[FRA_TABLE])
		rule.rule.action.table = *(uint32_t *)RTA_DATA(tb[FRA_TABLE]);
	else
		rule.rule.action.table = frh->table;

	if (IS_ZEBRA_DEBUG_KERNEL)
		zlog_debug(
			"Rx %s family %s IF %s(%u) Pref %u Src %s Dst %s Table %u",
			nl_msg_type_to_str(h->nlmsg_type),
			nl_family_to_str(frh->family), rule.ifp->name,
			rule.ifp->ifindex, rule.rule.priority,
			prefix2str(&rule.rule.filter.src_ip, buf1,
				   sizeof(buf1)),
			prefix2str(&rule.rule.filter.dst_ip, buf2,
				   sizeof(buf2)),
			rule.rule.action.table);

	return kernel_pbr_rule_del(&rule);
}