/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* bos72D src/bos/kernext/cluster/inc/cluster_user_net.h 1.12.2.11        */
/*                                                                        */
/* Licensed Materials - Property of IBM                                   */
/*                                                                        */
/* Restricted Materials of IBM                                            */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2010,2015              */
/* All Rights Reserved                                                    */
/*                                                                        */
/* US Government Users Restricted Rights - Use, duplication or            */
/* disclosure restricted by GSA ADP Schedule Contract with IBM Corp.      */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
/* @(#)35       1.12.2.11  src/bos/kernext/cluster/inc/cluster_user_net.h, sysxcluster, bos72D, d2015_38A0 9/11/15 14:01:21 */

#ifndef _CLUSTER_USER_NET_H
#define _CLUSTER_USER_NET_H

#include <sys/utsname.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/cfgdb.h>
#include <sys/ndd.h>
#include <sys/cluster.h>
#include <netinet/in.h>
#include <net/if.h>

#define AVIP        0x00000001
#define DVIP        0x00000002
#define APORT       0x00000004
#define DPORT       0x00000008
#define ATARGET     0x00000010
#define DTARGET     0x00000020
#define AIF         0x00000040
#define DIF         0x00000080
#define AEXCEPT     0x00000100
#define DEXCEPT     0x00000200
#define HSWITCH     0x00000400
#define NHDUMP      0x00000800
#define FHDUMP      0x00001000
#define STATDUMP    0x00002000
#define AEXIF       0x00004000
#define DEXIF       0x00008000



#ifndef ETHER_ADDR_LEN
#define ETHER_ADDR_LEN 6
#endif
#ifndef ISO88025_ADDR_LEN
#define ISO88025_ADDR_LEN 6
#endif

#define MAXNETMON   5

typedef struct t_addr_ip
{
    sa_family_t    the_family;
    union
    {
        struct in_addr ip4;
        struct in6_addr ip6;
    } t_ip;
} t_addr_ip_t, *t_addr_ip_p;

typedef struct t_addr_ip_all
{
    t_addr_ip_t addr;
    t_addr_ip_t bcast_addr;
    t_addr_ip_t netmask_addr;
} t_addr_ip_all_t, *t_addr_ip_all_p;

typedef struct t_addr_ip_mreq
{
    sa_family_t     the_family;
    in_port_t       the_port;
    union
    {
        struct ip_mreq ip_mreq4;
        struct ipv6_mreq ip_mreq6;
    } t_ip_mreq;
} t_addr_ip_mreq_t, *t_addr_ip_mreq_p;


typedef struct t_addr_mac
{
    union
    {
        u_char edst[ETHER_ADDR_LEN];
        u_char tdst[ISO88025_ADDR_LEN];
    } t_mac;
} t_addr_mac_t, *t_addr_mac_p;

typedef struct port_prot
{
    t_addr_ip_t vip;
    u_int32_t prot_h; /* high level protocol i.e. tcp/udp */
    u_int32_t prot_l; /* low level protocol expected at port i.e. nfs */
    u_int16_t port;
    u_int64_t node_list; /* list of nodes supporting vip. Just a int mask for now. */
} port_prot_t, *port_prot_p;

typedef struct vipaddr   /* cluster  virtual ip addresses of targets */
{
    t_addr_ip_t vip;
} vipaddr_t, *vipaddr_p;

typedef struct targ_addr   /* How cluster keeps detailed physical addresses of targets */
{
    u_int64_t   num;  /* nodeid of target */
    t_addr_ip_t     dst_ip; /* ip of target on interface network */
    t_addr_mac_t    mac; /* target mac (i.e. his) for interface */
    char        name[IFNAMSIZ]; /* name of interface to target for mac which follows */
} targ_addr_t, *targ_addr_p;

typedef struct if_detail   /* cluster details on network interfaces */
{
    char        name[NDD_MAXNAMELEN];
    u_int32_t   state; /* see states.h */
    u_int16_t   alen; /* mac length */
    u_int16_t   type1; /* see if.h */
    u_int16_t   type2; /* see ndd.h */
    u_int32_t   ndd_flags;
    u_int64_t   if_flags;
    short       srtt;
    short       lnk_srtt;
    short       rttvar;
    short       lnk_rttvar;
    u_int32_t   probe_interval;
    t_addr_mac_t    mac; /* mac for interface */
    u_int16_t   num_normal; /* number of regular addresses on interface. */
    u_int16_t   num_clust; /* number of cluster addresses on interface. */
    u_int16_t   num_multi; /* number of multicast address. */
    u_int16_t   dst_node_id; /* keep pad out */
    t_addr_ip_all_t cluster_addrs[1]; /* total addresses on the interface. num_normal + num_clust + num_multi long */
} if_detail_t, *if_detail_p;

typedef struct if_list   /* How cluster keeps network interface lists */
{
    char            node_name[MAXHOSTNAMELEN];
    t_wwid_t        node_uuid;
    t_addr_ip_t     node_pseudo_ip;  /* Pseudo IP Address */
    u_int32_t       num_if; /* Number of interfaces with cluster addresses */
    struct if_detail    if_detail[1]; /* Really num_if long */
} if_list_t, *if_list_p;

typedef struct if_list_cluster_hdr
{
    char            cluster_name[MAXHOSTNAMELEN];
    t_wwid_t        cluster_uuid;
    u_int32_t       num_nodes_reporting;
    u_int32_t       num_nodes_expected;
    u_int32_t       total_length_of_data; /* Including this header */
} if_list_cluster_hdr_t, *if_list_cluster_hdr_p;

typedef struct if_list_cluster   /* How cluster keeps network interface lists */
{
    if_list_cluster_hdr_t   list_hdr;
    struct if_list      if_list[1]; /*num_nodes_reporting long */
} if_list_cluster_t, *if_list_cluster_p;


typedef struct t_stat_net
{
    u_int64_t       seenpkts;
    u_int64_t       passpkts;
    u_int64_t       gossippkts_s;
    u_int64_t       uni_pkts_s;
    u_int64_t       rxmit_q_overflow_unicast;
    u_int64_t       gossippkts_r;
    u_int64_t       uni_pkts_r;
    u_int64_t       badxmit_dueto_overflow_tcpsock;
    u_int64_t       ippkts;
    u_int64_t       udppkts;
    u_int64_t       sancompkts_s;
    u_int64_t       sancompkts_r;
    u_int64_t       dpcompkts_r;
    u_int64_t       dpcompkts_s;
    u_int64_t       clustpkts;
    u_int64_t       ourpkts;
    u_int64_t       oobpkts;
    u_int64_t       badxmit;
    u_int64_t       lnk_badxmit;
    u_int64_t       badpost;
    u_int64_t       shortpkts;
    u_int64_t       lnk_shortpkts;
    u_int64_t       multipkts;
    u_int64_t       badpkts;
    u_int64_t       lnk_badpkts;
    u_int64_t       tcppkts;
    u_int64_t       fragpkts;
    u_int64_t       queuefrags;
    u_int64_t       freefrags;
    u_int64_t       dropkts;
    u_int64_t       pull;
    u_int64_t       nomem;
    u_int64_t       lnk_reqs_s;
    u_int64_t       reqs_s;
    u_int64_t       reqs_r;
    u_int64_t       reqs_lnk_r;
    u_int64_t       foundreqs;
    u_int64_t       lnk_foundreqs;
    u_int64_t       missreqs;
    u_int64_t       lnk_missreqs;
    u_int64_t       reset_r;
    u_int64_t       reset_s;
    u_int64_t       tcpsock_r;
    u_int64_t       tcpsock_s;
    u_int64_t       ahafspkts_s;
    u_int64_t       ahafspkts_r;
    u_int64_t       alivepkts_s;
    u_int64_t       lnk_alivepkts_s;
    u_int64_t       alivepkts_r;
    u_int64_t       lnk_alivepkts_r;
    u_int64_t       nodedownpkts_s;
    u_int64_t       lnk_nodedownpkts_s;
    u_int64_t       nodedownpkts_r;
    u_int64_t       lnk_nodedownpkts_r;
    u_int64_t       sockpkts_s;
    u_int64_t       sockpkts_r;
    u_int64_t       socknospace;
    u_int64_t       notforhere;
    u_int64_t       notforclust;
    u_int64_t       outofrange;
    u_int64_t       stale_pkts;
    u_int64_t       lnk_stale_pkts;
    u_int64_t       duppkts;
    u_int64_t       badcwide;
    u_int64_t       cluster_wide_pkts_s;
    u_int64_t       cluster_wide_pkts_r;
    u_int64_t       notforlink;
    u_int64_t       cluster_link_pkts_s;
    u_int64_t       cluster_link_pkts_r;
    u_int64_t       fragdropped;;
    u_int64_t       fragtimeout;
    u_int64_t       fragmented;
    u_int64_t       reassembled;
    u_int64_t       ofragments;
    u_int64_t       fragments;
    u_int64_t       badxmit_dueto_overflow;
    u_int64_t       badxmit_dueto_hostunreach;
    u_int64_t       badxmit_dueto_netdown;
    u_int64_t       pseudo_sockpkts_received;
    u_int64_t       pseudo_sockpkts_sent;
    u_int64_t       pseudo_sockpkts_dropped;
    u_int64_t       arppkts_received;
    u_int64_t       arppkts_sent;
    u_int64_t       badxmit_dueto_netunreach;
    u_int64_t       badxmit_dueto_enoconnect;
    u_int64_t       ipv6pkts_r;
    u_int64_t       ipv6pkts_s;
    u_int64_t       ipv6frags_r;
    u_int64_t       ipv6frags_s;
    u_int64_t       err_largepkt;
    u_int64_t       rxmit_q_overflow_mcast;
    u_int64_t       mcast_ping_pkts;
} t_stat_net_t, *t_stat_net_p;

typedef struct extern_addr   /* How cluster keeps EXTERNAL network interfaces */
{
    t_addr_ip_t ext_ip; /* ip of external network. This should not be a vip */
    char name[IFNAMSIZ]; /* name of interface to target for mac which follows */
} extern_addr_t, *extern_addr_p;

typedef struct if_netmon
{
    u_int32_t   num_ping; /* number of netmon ping address configured */
    t_addr_ip_t netmon_list[MAXNETMON];
} if_netmon_t, *if_netmon_p;

/**
 * Network address checking
 */
#define SAME_ADDR4(_a, _b)  (((_a).s_addr == (_b).s_addr))
#define SAME_SUBNET(_a, _b, _m)  (((_a).s_addr & (_m).s_addr) == ((_b).s_addr & (_m).s_addr))
#define SAME_SUBNET6(_a, _b, _m) \
      ((((_a).s6_addr32[0] & (_m).s6_addr32[0]) == ((_b).s6_addr32[0] & (_m).s6_addr32[0])) && \
       (((_a).s6_addr32[1] & (_m).s6_addr32[1]) == ((_b).s6_addr32[1] & (_m).s6_addr32[1])) && \
       (((_a).s6_addr32[2] & (_m).s6_addr32[2]) == ((_b).s6_addr32[2] & (_m).s6_addr32[2])) && \
       (((_a).s6_addr32[3] & (_m).s6_addr32[3]) == ((_b).s6_addr32[3] & (_m).s6_addr32[3])))
#define SAME_ADDR(_a, _b) \
      (((_a).the_family == AF_INET) ? \
       (SAME_ADDR4((_a).t_ip.ip4, (_b).t_ip.ip4)):(SAME_ADDR6((_a).t_ip.ip6, (_b).t_ip.ip6)))

#endif /* _CLUSTER_USER_NET_H */