if.h revision 3a18a1c198c1b0bc47599d4a37028047fc8358cc
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright (c) 1982, 1986 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*/
#ifndef _NET_IF_H
#define _NET_IF_H
/* if.h 1.26 90/05/29 SMI; from UCB 7.1 6/4/86 */
#include <sys/feature_tests.h>
#if !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__)
#if defined(_LP64)
#endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
/*
* Structures defining a network interface, providing a packet
* transport mechanism (ala level 0 of the PUP protocols).
*
* Each interface accepts output datagrams of a specified maximum
* length, and provides higher level routines with input datagrams
* received from its medium.
*
* Output occurs when the routine if_output is called, with three parameters:
* (*ifp->if_output)(ifp, m, dst)
* Here m is the mbuf chain to be sent and dst is the destination address.
* The output routine encapsulates the supplied datagram if necessary,
* and then transmits it on its medium.
*
* On input, each interface unwraps the data received by it, and either
* places it on the input queue of a internetwork datagram routine
* and posts the associated software interrupt, or passes the datagram to a raw
* packet input routine.
*
* Routines exist for locating interfaces by their addresses
* or for locating a interface on a certain network, as well as more general
* routing and gateway routines maintaining information used to locate
*/
#if !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__)
/*
* Structure defining a queue for a network interface.
*
* (Would like to call this struct ``if'', but C isn't PL/1.)
*/
struct ifnet {
char *if_name; /* name, e.g. ``en'' or ``lo'' */
short if_unit; /* sub-unit for lower level driver */
short if_mtu; /* maximum transmission unit */
short if_timer; /* time 'til if_watchdog called */
int if_metric; /* routing metric (external only) */
struct ifqueue {
int ifq_len;
int ifq_maxlen;
int ifq_drops;
} if_snd; /* output queue */
/* procedure handles */
int (*if_init)(); /* init routine */
int (*if_output)(); /* output routine */
int (*if_ioctl)(); /* ioctl routine */
int (*if_reset)(); /* bus reset routine */
int (*if_watchdog)(); /* timer routine */
/* generic interface statistics */
int if_ipackets; /* packets received on interface */
int if_ierrors; /* input errors on interface */
int if_opackets; /* packets sent on interface */
int if_oerrors; /* output errors on interface */
int if_collisions; /* collisions on csma interfaces */
/* end statistics */
int (*if_input)(); /* input routine */
int (*if_ctlin)(); /* control input routine */
int (*if_ctlout)(); /* control output routine */
};
/*
* NOTE : These flags are not directly used within IP.
* ip_if.h has definitions derived from this which is used within IP.
* If you define a flag here, you need to define one in ip_if.h before
* using the new flag in IP. Don't use these flags directly in IP.
*/
/*
* The IFF_MULTICAST flag indicates that the network can support the
* transmission and reception of higher-level (e.g., IP) multicast packets.
* It is independent of hardware support for multicasting; for example,
* point-to-point links or pure broadcast networks may well support
* higher-level multicasts.
*/
/*
* The following flags can't be grabbed or altered by SIOC[GS]IFFLAGS.
* Should use SIOC[GS]LIFFLAGS which has a larger flags field.
*/
/* 0x0004000000 was IFF_MIPRUNNING */
/*
* The IFF_XRESOLV flag is an evolving interface and is subject
* to change without notice.
*/
/* flags that cannot be changed by userland on any interface */
#define IFF_CANTCHANGE \
/* flags that cannot be changed by userland on an IPMP interface */
#define IFF_IPMP_CANTCHANGE IFF_FAILED
/* flags that can never be set on an IPMP interface */
/*
* Output queues (ifp->if_snd) and internetwork datagram level (pup level 1)
* input routines have queues of messages stored on ifqueue structures
* (defined above). Entries are added to and deleted from these structures
* by these macros, which should be called with ipl raised to splimp().
*/
#define IF_ENQUEUE(ifq, m) { \
(m)->m_act = 0; \
else \
}
#define IF_PREPEND(ifq, m) { \
}
/*
* Packets destined for level-1 protocol input routines
* have a pointer to the receiving interface prepended to the data.
* IF_DEQUEUEIF extracts and returns this pointer when dequeuing the packet.
* IF_ADJ should be used otherwise to adjust for its presence.
*/
#define IF_ADJ(m) { \
if ((m)->m_len == 0) { \
struct mbuf *n; \
MFREE((m), n); \
(m) = n; \
} \
}
if (m) { \
(m)->m_act = 0; \
IF_ADJ(m); \
} \
}
#define IF_DEQUEUE(ifq, m) { \
if (m) { \
(m)->m_act = 0; \
} \
}
#define IFQ_MAXLEN 50
/*
* The ifaddr structure contains information about one address
* of an interface. They are maintained by the different address families,
* are allocated and attached when an address is set, and are linked
* together so all addresses for an interface can be located.
*/
struct ifaddr {
union {
struct sockaddr ifu_broadaddr;
struct sockaddr ifu_dstaddr;
} ifa_ifu;
};
/*
* For SIOCLIF*ND ioctls.
*
* The lnr_state_* fields use the ND_* neighbor reachability states.
* The 3 different fields are for use with SIOCLIFSETND to cover the cases
* when
* A new entry is created
* The entry already exists and the link-layer address is the same
* The entry already exists and the link-layer address differs
*
* Use ND_UNCHANGED and ND_ISROUTER_UNCHANGED to not change any state.
*/
#define ND_MAX_HDW_LEN 64
typedef struct lif_nd_req {
struct sockaddr_storage lnr_addr;
int lnr_hdw_len;
int lnr_flags; /* See below */
/* padding because ia32 "long long"s are only 4-byte aligned. */
int lnr_pad0;
char lnr_hdw_addr[ND_MAX_HDW_LEN];
} lif_nd_req_t;
/*
* Neighbor reachability states
* Used with SIOCLIF*ND ioctls.
*/
#define ND_UNCHANGED 0 /* For ioctls that don't modify state */
#define ND_STATE_VALID_MIN 0
#define ND_STATE_VALID_MAX 7
/*
* lnr_flags value of lif_nd_req.
* Used with SIOCLIF*ND ioctls.
*/
#define NDF_ISROUTER_ON 0x1
#define NDF_ISROUTER_OFF 0x2
#define NDF_ANYCAST_ON 0x4
#define NDF_ANYCAST_OFF 0x8
#define NDF_PROXY_ON 0x10
#define NDF_PROXY_OFF 0x20
/* For SIOC[GS]LIFLNKINFO */
typedef struct lif_ifinfo_req {
#endif /* !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__) */
/*
* Maximum lengths of interface name and IPMP group name; these are the same
* for historical reasons. Note that the actual maximum length of a name is
* one byte less than these constants since the kernel always sets the final
* byte of lifr_name and lifr_groupname to NUL.
*/
#define _LIFNAMSIZ 32
#if !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__)
#define LIFNAMSIZ _LIFNAMSIZ
#define LIFGRNAMSIZ LIFNAMSIZ
/*
* Interface request structure used for socket
* ioctl's. All interface ioctl's must have parameter
* definitions which begin with ifr_name. The
* remainder may be interface specific.
* Note: This data structure uses 64bit type uint64_t which is not
* Applications with ioctls using this structure that insist on
*/
#if defined(_INT64_TYPE)
struct lifreq {
union {
int lifru_addrlen; /* for subnet/token etc */
} lifr_lifru1;
union {
struct sockaddr_storage lifru_addr;
struct sockaddr_storage lifru_dstaddr;
struct sockaddr_storage lifru_broadaddr;
int lifru_index; /* interface index */
int lifru_metric;
struct lif_nd_req lifru_nd_req;
struct lif_ifinfo_req lifru_ifinfo_req;
} lifr_lifru;
};
#endif /* defined(_INT64_TYPE) */
/*
* Argument structure for SIOCT* address testing ioctls.
*/
struct sioc_addrreq {
int sa_res; /* Result - 0/1 */
int sa_pad;
};
/*
* Argument structure used by mrouted to get src-grp pkt counts using
* SIOCGETLSGCNT. See <netinet/ip_mroute.h>.
*/
struct sioc_lsg_req {
struct sockaddr_storage slr_src;
struct sockaddr_storage slr_grp;
};
/*
* OBSOLETE: Replaced by struct lifreq. Supported for compatibility.
*
* Interface request structure used for socket
* ioctl's. All interface ioctl's must have parameter
* definitions which begin with ifr_name. The
* remainder may be interface specific.
*/
struct ifreq {
#define IFNAMSIZ 16
union {
struct sockaddr ifru_dstaddr;
struct sockaddr ifru_broadaddr;
int ifru_index; /* interface index */
short ifru_flags;
int ifru_metric;
char ifru_enaddr[6];
struct ifr_ppaflags {
short ifrup_flags; /* Space of ifru_flags. */
short ifrup_filler;
/* Struct for FDDI ioctl's */
struct ifr_dnld_reqs {
/* Struct for FDDI stats */
struct ifr_fddi_stats {
struct ifr_netmapents {
entry_number; /* index into netmap list */
/* Field for generic ioctl for fddi */
struct ifr_fddi_gen_struct {
} ifr_ifru;
/* For setting ppa */
/* FDDI specific */
};
/* Used by SIOCGLIFNUM. Uses same flags as in struct lifconf */
struct lifnum {
int lifn_flags; /* request specific interfaces */
int lifn_count; /* Result */
};
/*
* Structure used in SIOCGLIFCONF request.
* Used to retrieve interface configuration
* for machine (useful for programs which
* must know all networks accessible) for a given address family.
* Using AF_UNSPEC will retrieve all address families.
*/
struct lifconf {
int lifc_flags; /* request specific interfaces */
int lifc_len; /* size of associated buffer */
union {
} lifc_lifcu;
};
/*
* Structure used in SIOCGLIFSRCOF to get the interface
* configuration list for those interfaces that use an address
* hosted on the interface (set in lifs_ifindex), as the source
* address.
*/
struct lifsrcof {
union {
} lifs_lifsu;
};
/* Flags */
/* be used to communicate outside the */
/* node (exclude interfaces which are */
/* IFF_NOXMIT, IFF_NOLOCAL, */
/* IFF_LOOPBACK, IFF_DEPRECATED, or */
/* not IFF_UP). Has priority over */
/* LIFC_NOXMIT. */
/* (must be issued from global zone) */
#if defined(_SYSCALL32)
struct lifconf32 {
int lifc_flags; /* request specific interfaces */
union {
} lifc_lifcu;
};
struct lifsrcof32 {
union {
} lifs_lifsu;
};
#endif /* _SYSCALL32 */
/*
* IPMP group information, for use with SIOCGLIFGROUPINFO.
*/
typedef struct lifgroupinfo {
/*
* OBSOLETE: Structure used in SIOCGIFCONF request.
* Used to retrieve interface configuration
* for machine (useful for programs which
* must know all networks accessible).
*/
struct ifconf {
int ifc_len; /* size of associated buffer */
union {
} ifc_ifcu;
};
#if defined(_SYSCALL32)
struct ifconf32 {
union {
} ifc_ifcu;
};
#endif /* _SYSCALL32 */
typedef struct if_data {
/* generic interface information */
/* volatile statistics */
#if defined(_LP64)
#else
#endif
} if_data_t;
/*
* Message format for use in obtaining information about interfaces
* from the routing socket
*/
typedef struct if_msghdr {
int ifm_addrs; /* like rtm_addrs */
int ifm_flags; /* value of if_flags */
} if_msghdr_t;
/*
* Message format for use in obtaining information about interface addresses
* from the routing socket
*/
typedef struct ifa_msghdr {
int ifam_addrs; /* like rtm_addrs */
int ifam_flags; /* route flags */
int ifam_metric; /* value of ipif_metric */
} ifa_msghdr_t;
/* currently tunnels only support IPv4 or IPv6 */
enum ifta_proto {
};
/*
* SIOCTUN[SG]PARAM.
*
* There is a version number and an array of uint32_t at the end of this
* ioctl because in a perfect world, the ipsec_req_t would be inside
* tun_addreq. Since this file is independent of IP (and IPsec), I have to
* just leave room there, and have the appropriate handlers deal with the
* security information.
*
* In the future, the sockaddr types and the ta_vers could be used together
* to determine the nature of the security information that is at the end
* of this ioctl.
*/
struct iftun_req {
/* IP version information is read only */
};
/* ifta_flags are set to indicate which members are valid */
#define IFTUN_SRC 0x01
#define IFTUN_DST 0x02
#endif /* !defined(_XOPEN_SOURCE) || defined(__EXTENSIONS__) */
/*
* The if_nameindex structure holds the interface index value about
* a single interface. An array of this structure is used to return
* all interfaces and indexes.
*/
struct if_nameindex {
unsigned if_index; /* positive interface index */
char *if_name; /* if name, e.g. "en0" */
};
/* Interface index identification API definitions */
extern unsigned if_nametoindex(const char *);
extern char *if_indextoname(unsigned, char *);
extern struct if_nameindex *if_nameindex(void);
extern void if_freenameindex(struct if_nameindex *);
#define IF_NAMESIZE _LIFNAMSIZ
#ifdef __cplusplus
}
#endif
#endif /* _NET_IF_H */