18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * net/tipc/addr.h: Include file for TIPC address utility routines
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright (c) 2000-2006, 2018, Ericsson AB
58c2ecf20Sopenharmony_ci * Copyright (c) 2004-2005, Wind River Systems
68c2ecf20Sopenharmony_ci * All rights reserved.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
98c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions are met:
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright
128c2ecf20Sopenharmony_ci *    notice, this list of conditions and the following disclaimer.
138c2ecf20Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright
148c2ecf20Sopenharmony_ci *    notice, this list of conditions and the following disclaimer in the
158c2ecf20Sopenharmony_ci *    documentation and/or other materials provided with the distribution.
168c2ecf20Sopenharmony_ci * 3. Neither the names of the copyright holders nor the names of its
178c2ecf20Sopenharmony_ci *    contributors may be used to endorse or promote products derived from
188c2ecf20Sopenharmony_ci *    this software without specific prior written permission.
198c2ecf20Sopenharmony_ci *
208c2ecf20Sopenharmony_ci * Alternatively, this software may be distributed under the terms of the
218c2ecf20Sopenharmony_ci * GNU General Public License ("GPL") version 2 as published by the Free
228c2ecf20Sopenharmony_ci * Software Foundation.
238c2ecf20Sopenharmony_ci *
248c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
258c2ecf20Sopenharmony_ci * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
268c2ecf20Sopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
278c2ecf20Sopenharmony_ci * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
288c2ecf20Sopenharmony_ci * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
298c2ecf20Sopenharmony_ci * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
308c2ecf20Sopenharmony_ci * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
318c2ecf20Sopenharmony_ci * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
328c2ecf20Sopenharmony_ci * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
338c2ecf20Sopenharmony_ci * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
348c2ecf20Sopenharmony_ci * POSSIBILITY OF SUCH DAMAGE.
358c2ecf20Sopenharmony_ci */
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci#ifndef _TIPC_ADDR_H
388c2ecf20Sopenharmony_ci#define _TIPC_ADDR_H
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci#include <linux/types.h>
418c2ecf20Sopenharmony_ci#include <linux/tipc.h>
428c2ecf20Sopenharmony_ci#include <net/net_namespace.h>
438c2ecf20Sopenharmony_ci#include <net/netns/generic.h>
448c2ecf20Sopenharmony_ci#include "core.h"
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cistatic inline u32 tipc_own_addr(struct net *net)
478c2ecf20Sopenharmony_ci{
488c2ecf20Sopenharmony_ci	return tipc_net(net)->node_addr;
498c2ecf20Sopenharmony_ci}
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_cistatic inline u8 *tipc_own_id(struct net *net)
528c2ecf20Sopenharmony_ci{
538c2ecf20Sopenharmony_ci	struct tipc_net *tn = tipc_net(net);
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci	if (!strlen(tn->node_id_string))
568c2ecf20Sopenharmony_ci		return NULL;
578c2ecf20Sopenharmony_ci	return tn->node_id;
588c2ecf20Sopenharmony_ci}
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_cistatic inline char *tipc_own_id_string(struct net *net)
618c2ecf20Sopenharmony_ci{
628c2ecf20Sopenharmony_ci	return tipc_net(net)->node_id_string;
638c2ecf20Sopenharmony_ci}
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_cistatic inline u32 tipc_cluster_mask(u32 addr)
668c2ecf20Sopenharmony_ci{
678c2ecf20Sopenharmony_ci	return addr & TIPC_ZONE_CLUSTER_MASK;
688c2ecf20Sopenharmony_ci}
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_cistatic inline int tipc_node2scope(u32 node)
718c2ecf20Sopenharmony_ci{
728c2ecf20Sopenharmony_ci	return node ? TIPC_NODE_SCOPE : TIPC_CLUSTER_SCOPE;
738c2ecf20Sopenharmony_ci}
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_cistatic inline int tipc_scope2node(struct net *net, int sc)
768c2ecf20Sopenharmony_ci{
778c2ecf20Sopenharmony_ci	return sc != TIPC_NODE_SCOPE ? 0 : tipc_own_addr(net);
788c2ecf20Sopenharmony_ci}
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_cistatic inline int in_own_node(struct net *net, u32 addr)
818c2ecf20Sopenharmony_ci{
828c2ecf20Sopenharmony_ci	return addr == tipc_own_addr(net) || !addr;
838c2ecf20Sopenharmony_ci}
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_cibool tipc_in_scope(bool legacy_format, u32 domain, u32 addr);
868c2ecf20Sopenharmony_civoid tipc_set_node_id(struct net *net, u8 *id);
878c2ecf20Sopenharmony_civoid tipc_set_node_addr(struct net *net, u32 addr);
888c2ecf20Sopenharmony_cichar *tipc_nodeid2string(char *str, u8 *id);
898c2ecf20Sopenharmony_ciu32 tipc_node_id2hash(u8 *id128);
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci#endif
92