+#ifdef KERNEL_PRIVATE
+/******************************************************************************/
+/* interface cloner */
+/******************************************************************************/
+
+/*
+ @typedef ifnet_clone_create_func
+ @discussion ifnet_clone_create_func is called to create an interface.
+ @param ifcloner The interface cloner.
+ @param unit The interface unit number to create.
+ @param params Additional information specific to the interface cloner.
+ @result Return zero on success or an errno error value on failure.
+ */
+typedef errno_t (*ifnet_clone_create_func)(if_clone_t ifcloner, u_int32_t unit, void *params);
+
+/*
+ @typedef ifnet_clone_destroy_func
+ @discussion ifnet_clone_create_func is called to destroy an interface created
+ by an interface cloner.
+ @param interface The interface to destroy.
+ @result Return zero on success or an errno error value on failure.
+ */
+typedef errno_t (*ifnet_clone_destroy_func)(ifnet_t interface);
+
+/*
+ @struct ifnet_clone_params
+ @discussion This structure is used to represent an interface cloner.
+ @field ifc_name The interface name handled by this interface cloner.
+ @field ifc_create The function to create an interface.
+ @field ifc_destroy The function to destroy an interface.
+*/
+struct ifnet_clone_params {
+ const char *ifc_name;
+ ifnet_clone_create_func ifc_create;
+ ifnet_clone_destroy_func ifc_destroy;
+};
+
+/*
+ @function ifnet_clone_attach
+ @discussion Attaches a new interface cloner.
+ @param cloner_params The structure that defines an interface cloner.
+ @param interface A pointer to an opaque handle that represent the interface cloner
+ that is attached upon success.
+ @result Returns 0 on success.
+ May return ENOBUFS if there is insufficient memory.
+ May return EEXIST if an interface cloner with the same name is already attached.
+ */
+extern errno_t ifnet_clone_attach(struct ifnet_clone_params *cloner_params, if_clone_t *ifcloner);
+
+/*
+ @function ifnet_clone_detach
+ @discussion Detaches a previously attached interface cloner.
+ @param ifcloner The opaque handle returned when the interface cloner was attached.
+ @result Returns 0 on success.
+ */
+extern errno_t ifnet_clone_detach(if_clone_t ifcloner);
+
+/******************************************************************************/
+/* misc */
+/******************************************************************************/
+
+/*
+ @function ifnet_get_local_ports
+ @discussion Returns a bitfield indicating which ports of PF_INET
+ and PF_INET6 protocol families have sockets in the usable
+ state. An interface that supports waking the host on unicast
+ traffic may use this information to discard incoming unicast
+ packets that don't have a corresponding bit set instead of
+ waking up the host. For port 0x0001, bit 1 of the first byte
+ would be set. For port n, bit 1 << (n % 8) of the (n / 8)'th
+ byte would be set.
+ @param ifp The interface in question. May be NULL, which means
+ all interfaces.
+ @param bitfield A pointer to 8192 bytes.
+ @result Returns 0 on success.
+ */
+extern errno_t ifnet_get_local_ports(ifnet_t ifp, u_int8_t *bitfield);
+
+#define IFNET_GET_LOCAL_PORTS_WILDCARDOK 0x01
+#define IFNET_GET_LOCAL_PORTS_NOWAKEUPOK 0x02
+#define IFNET_GET_LOCAL_PORTS_TCPONLY 0x04
+#define IFNET_GET_LOCAL_PORTS_UDPONLY 0x08
+#define IFNET_GET_LOCAL_PORTS_RECVANYIFONLY 0x10
+#define IFNET_GET_LOCAL_PORTS_EXTBGIDLEONLY 0x20
+#define IFNET_GET_LOCAL_PORTS_ACTIVEONLY 0x40
+/*
+ @function ifnet_get_local_ports_extended
+ @discussion Returns a bitfield indicating which local ports of the
+ specified protocol have sockets in the usable state. An
+ interface that supports waking the host on unicast traffic may
+ use this information to discard incoming unicast packets that
+ don't have a corresponding bit set instead of waking up the
+ host. For port 0x0001, bit 1 of the first byte would be set.
+ For port n, bit 1 << (n % 8) of the (n / 8)'th byte would be
+ set.
+ @param ifp The interface in question. May be NULL, which means
+ all interfaces.
+ @param protocol The protocol family of the sockets. PF_UNSPEC (0)
+ means all protocols, otherwise PF_INET or PF_INET6.
+ @param flags A bitwise of the following flags:
+ IFNET_GET_LOCAL_PORTS_WILDCARDOK: When bit is set,
+ the list of local ports should include those that are
+ used by sockets that aren't bound to any local address.
+ IFNET_GET_LOCAL_PORTS_NOWAKEUPOK: When bit is
+ set, the list of local ports should return all sockets
+ including the ones that do not need a wakeup from sleep.
+ Sockets that do not want to wake from sleep are marked
+ with a socket option.
+ IFNET_GET_LOCAL_PORTS_TCPONLY: When bit is set, the list
+ of local ports should return the ports used by TCP sockets.
+ IFNET_GET_LOCAL_PORTS_UDPONLY: When bit is set, the list
+ of local ports should return the ports used by UDP sockets.
+ only.
+ IFNET_GET_LOCAL_PORTS_RECVANYIFONLY: When bit is set, the
+ port is in the list only if the socket has the option
+ SO_RECV_ANYIF set
+ IFNET_GET_LOCAL_PORTS_EXTBGIDLEONLY: When bit is set, the
+ port is in the list only if the socket has the option
+ SO_EXTENDED_BK_IDLE set
+ IFNET_GET_LOCAL_PORTS_ACTIVEONLY: When bit is set, the
+ port is in the list only if the socket is not in a final TCP
+ state or the connection is not idle in a final TCP state
+ @param bitfield A pointer to 8192 bytes.
+ @result Returns 0 on success.
+ */
+extern errno_t ifnet_get_local_ports_extended(ifnet_t ifp,
+ protocol_family_t protocol, u_int32_t flags, u_int8_t *bitfield);
+
+/******************************************************************************/
+/* for reporting issues */
+/******************************************************************************/
+
+#define IFNET_MODIDLEN 20
+#define IFNET_MODARGLEN 12
+
+/*
+ @function ifnet_report_issues
+ @discussion Provided for network interface families and drivers to
+ notify the system of issues detected at their layers.
+ @param ifp The interface experiencing issues.
+ @param modid The ID of the module reporting issues. It may contain
+ any value that is unique enough to identify the module, such
+ as the SHA-1 hash of the bundle ID of the module, e.g.
+ "com.apple.iokit.IONetworkingFamily" or
+ "com.apple.iokit.IO80211Family".
+ @param info An optional, fixed-size array of octets containing opaque
+ information data used specific to the module/layer reporting
+ the issues. May be NULL.
+ @result Returns 0 on success, or EINVAL if arguments are invalid.
+ */
+extern errno_t ifnet_report_issues(ifnet_t ifp, u_int8_t modid[IFNET_MODIDLEN],
+ u_int8_t info[IFNET_MODARGLEN]);
+
+/******************************************************************************/
+/* for interfaces that support link level transmit completion status */
+/******************************************************************************/
+/*
+ @enum Per packet phy level transmit completion status values
+ @abstract Constants defining possible completion status values
+ A driver may support all or some of these values
+ @discussion
+ @constant IFNET_TX_COMPL_SUCCESS link transmission succeeded
+ @constant IFNET_TX_COMPL_FAIL link transmission failed
+ @constant IFNET_TX_COMPL_ABORTED link transmission aborted, may retry
+ @constant IFNET_TX_QUEUE_FULL link level secondary queue full
+*/
+enum {
+ IFNET_TX_COMPL_SUCCESS = 0, /* sent on link */
+ IFNET_TX_COMPL_FAIL = 1, /* failed to send on link */
+ IFNET_TX_COMPL_ABORTED = 2, /* aborted send, peer asleep */
+ IFNET_TX_COMPL_QFULL = 3 /* driver level queue full */
+};
+
+typedef u_int32_t tx_compl_val_t;
+
+/*
+ @function ifnet_tx_compl_status
+ @discussion Used as an upcall from IONetwork Family to stack that
+ indicates the link level completion status of a transmitted
+ packet.
+ @param ifp The interface to which the mbuf was sent
+ @param m The mbuf that was transmitted
+ @param val indicates the status of the transmission
+*/
+extern errno_t ifnet_tx_compl_status(ifnet_t ifp, mbuf_t m, tx_compl_val_t val);
+
+/*
+ @function ifnet_tx_compl
+ @discussion Used to indicates the packet has been transmitted.
+ @param ifp The interface to which the mbuf was sent
+ @param m The mbuf that was transmitted
+*/
+extern errno_t ifnet_tx_compl(ifnet_t ifp, mbuf_t m);
+
+/******************************************************************************/
+/* for interfaces that support dynamic node absence/presence events */
+/******************************************************************************/
+
+/*
+ @function ifnet_notice_node_presence
+ @discussion Provided for network interface drivers to notify the
+ system of a change detected in the presence of the specified
+ node.
+ @param ifp The interface attached to the link where the specified node
+ is present.
+ @param sa The AF_LINK family address of the node whose presence is
+ changing.
+ @param rssi The received signal strength indication as measured in
+ dBm by a radio receiver.
+ @param lqm A link quality metric associated with the specified node.
+ @param npm A node proximity metric associated with the specified node.
+ @param srvinfo A fixed-size array of octets containing opaque service
+ information data used by the mDNS responder subsystem.
+ @result Returns 0 on success, or EINVAL if arguments are invalid.
+ */
+extern errno_t
+ifnet_notice_node_presence(ifnet_t ifp, struct sockaddr *sa, int32_t rssi,
+ int lqm, int npm, u_int8_t srvinfo[48]);
+
+/*
+ @function ifnet_notice_node_absence
+ @discussion Provided for network interface drivers to notify the
+ system that the absence of the specified node has been detected.
+ @param ifp The interface attached to the link where the absence of the
+ specified node has been detected.
+ @param sa The AF_LINK family address of the node whose absence has been
+ detected.
+ @result Returns 0 on success, or EINVAL if arguments are invalid.
+ */
+extern errno_t ifnet_notice_node_absence(ifnet_t ifp, struct sockaddr *sa);
+
+/*
+ @function ifnet_notice_master_elected
+ @discussion Provided for network interface drivers to notify the system
+ that the nodes with a locally detected presence on the attached
+ link have elected a new master.
+ @param ifp The interface attached to the link where the new master has
+ been elected.
+ @result Returns 0 on success, or EINVAL if arguments are invalid.
+ */
+extern errno_t ifnet_notice_master_elected(ifnet_t ifp);
+
+/******************************************************************************/
+/* for interface delegation */
+/******************************************************************************/
+
+/*
+ @function ifnet_set_delegate
+ @discussion Indicate that an interface is delegating another interface
+ for accounting/restriction purposes. This could be used by a
+ virtual interface that is going over another interface, where
+ the virtual interface is to be treated as if it's the underlying
+ interface for certain operations/checks.
+ @param ifp The delegating interface.
+ @param delegated_ifp The delegated interface. If NULL or equal to
+ the delegating interface itself, any previously-established
+ delegation is removed. If non-NULL, a reference to the
+ delegated interface is held by the delegating interface;
+ this reference is released via a subsequent call to remove
+ the established association, or when the delegating interface
+ is detached.
+ @param Returns 0 on success, EINVAL if arguments are invalid, or
+ ENXIO if the delegating interface isn't currently attached.
+ */
+extern errno_t
+ifnet_set_delegate(ifnet_t ifp, ifnet_t delegated_ifp);
+
+/*
+ @function ifnet_get_delegate
+ @discussion Retrieve delegated interface information on an interface.
+ @param ifp The delegating interface.
+ @param pdelegated_ifp Pointer to the delegated interface. Upon
+ success, this will contain the delegated interface or
+ NULL if there is no delegation in place. If non-NULL,
+ the delegated interface will be returned with a reference
+ held for caller, and the caller is responsible for releasing
+ it via ifnet_release();
+ @param Returns 0 on success, EINVAL if arguments are invalid, or
+ ENXIO if the delegating interface isn't currently attached.
+ */
+extern errno_t
+ifnet_get_delegate(ifnet_t ifp, ifnet_t *pdelegated_ifp);
+
+/*************************************************************************/
+/* for interface keep alive offload support */
+/*************************************************************************/
+
+/*
+ @struct ifnet_keepalive_offload_frame
+ @discussion This structure is used to define various opportunistic
+ polling parameters for an interface.
+ For IPSec and AirPlay UDP keep alive only a subset of the
+ fields are relevant.
+ An incoming TCP keep alive probe has the sequence number
+ in the TCP header equal to "remote_seq" and the
+ acknowledgment number field is equal to "local_seq".
+ An incoming TCP keep alive probe has the sequence number
+ equlal to "remote_seq" minus 1 and the acknowledgment number
+ field is equal to "local_seq".
+ Note that remote_seq is in network byte order so the value to
+ match may have to be converted to host byte order when
+ subtracting 1.
+ For TCP, the field "interval" corresponds to the socket option
+ TCP_KEEPALIVE, the field "keep_cnt" to TCP_KEEPINTVL and
+ the field "keep_cnt" to TCP_KEEPCNT.
+ @field data Keep alive probe to be sent.
+ @field type The type of keep alive frame
+ @field length The length of the frame in the data field
+ @field interval Keep alive interval between probes in seconds
+ @field ether_type Tell if it's the protocol is IPv4 or IPv6
+ @field keep_cnt Maximum number of time to retry probes (TCP only)
+ @field keep_retry Interval before retrying if previous probe was not answered (TCP only)
+ @field reply_length The length of the frame in the reply_data field (TCP only)
+ @field addr_length Length in bytes of local_addr and remote_addr (TCP only)
+ @field reply_data Keep alive reply to be sent to incoming probe (TCP only)
+ @field local_addr Local address: 4 bytes IPv4 or 16 bytes IPv6 address (TCP only)
+ @field remote_addr Remote address: 4 bytes IPv4 or 16 bytes IPv6 address (TCP only)
+ @field local_port Local port (TCP only)
+ @field remote_port Remote port (TCP only)
+ @field local_seq Local sequence number for matching incoming replies (TCP only)
+ @field remote_seq Remote sequence number for matching incoming probes or replies (TCP only)
+*/
+
+#define IFNET_KEEPALIVE_OFFLOAD_FRAME_DATA_SIZE 128
+#define IFNET_KEEPALIVE_OFFLOAD_MAX_ADDR_SIZE 16
+
+struct ifnet_keepalive_offload_frame {
+ u_int8_t data[IFNET_KEEPALIVE_OFFLOAD_FRAME_DATA_SIZE]; /* data bytes */
+#define IFNET_KEEPALIVE_OFFLOAD_FRAME_IPSEC 0x0
+#define IFNET_KEEPALIVE_OFFLOAD_FRAME_AIRPLAY 0x1
+#define IFNET_KEEPALIVE_OFFLOAD_FRAME_TCP 0x2
+ u_int8_t type; /* type of application */
+ u_int8_t length; /* Number of valid data bytes including offset */
+ u_int16_t interval; /* Keep alive interval in seconds */
+#define IFNET_KEEPALIVE_OFFLOAD_FRAME_ETHERTYPE_IPV4 0x0
+#define IFNET_KEEPALIVE_OFFLOAD_FRAME_ETHERTYPE_IPV6 0x1
+ u_int8_t ether_type; /* Ether type IPv4 or IPv6 */
+ u_int8_t keep_cnt; /* max number of time to retry probes */
+ u_int16_t keep_retry; /* interval before retrying if previous probe was not answered */
+ u_int8_t reply_length; /* Length of valid reply_data bytes including offset */
+ u_int8_t addr_length; /* Length of valid bytes in local_addr and remote_addr */
+ u_int8_t reserved[2];
+ u_int8_t reply_data[IFNET_KEEPALIVE_OFFLOAD_FRAME_DATA_SIZE]; /* Response packet */
+ u_int8_t local_addr[IFNET_KEEPALIVE_OFFLOAD_MAX_ADDR_SIZE]; /* in network byte order */
+ u_int8_t remote_addr[IFNET_KEEPALIVE_OFFLOAD_MAX_ADDR_SIZE]; /* in network byte order */
+ u_int16_t local_port; /* in host byte order */
+ u_int16_t remote_port; /* in host byte order */
+ u_int32_t local_seq; /* in host byte order */
+ u_int32_t remote_seq; /* in host byte order */
+};
+
+/*
+ @function ifnet_get_keepalive_offload_frames
+ @discussion Fills out frames_array with IP packets to send at
+ periodic intervals as Keep-alive or heartbeat messages.
+ This can be used to offload keep alives for UDP or TCP.
+ Note: The frames are returned in this order: first the IPSec
+ frames, then the AirPlay frames and finally the TCP frames.
+ If a device does not support one kind of keep alive frames_array
+ it should provide a frames_array large enough to accomodate
+ the other frames
+ @param ifp The interface to send frames out on. This is used to
+ select which sockets or IPSec SAs should generate the
+ packets.
+ @param frames_array An array of ifnet_keepalive_offload_frame
+ structs. This is allocated by the caller, and has
+ frames_array_count frames of valid memory.
+ @param frames_array_count The number of valid frames allocated
+ by the caller in frames_array
+ @param frame_data_offset The offset in bytes into each frame data
+ at which the IPv4/IPv6 packet and payload should be written
+ @param used_frames_count The returned number of frames that were
+ filled out with valid information.
+ @result Returns 0 on success, error number otherwise.
+*/
+extern errno_t ifnet_get_keepalive_offload_frames(ifnet_t ifp,
+ struct ifnet_keepalive_offload_frame *frames_array,
+ u_int32_t frames_array_count, size_t frame_data_offset,
+ u_int32_t *used_frames_count);
+
+/*************************************************************************/
+/* Link level notifications */
+/*************************************************************************/
+/*
+ @function ifnet_link_status_report
+ @discussion A KPI to let the driver provide link specific
+ status information to the protocol stack. The KPI will
+ copy contents from the buffer based on the version and
+ length provided by the driver. The contents of the buffer
+ will be read but will not be modified.
+ @param ifp The interface that is generating the report
+ @param buffer Buffer containing the link specific information
+ for this interface. It is the caller's responsibility
+ to free this buffer.
+ @param buffer_len Valid length of the buffer provided by the caller
+ @result Returns 0 on success, error number otherwise.
+*/
+extern errno_t ifnet_link_status_report(ifnet_t ifp, const void *buffer,
+ size_t buffer_len);
+
+/*************************************************************************/
+/* QoS Fastlane */
+/*************************************************************************/
+/*!
+ @function ifnet_set_fastlane_capable
+ @param interface The interface.
+ @param capable Set the truth value that the interface is attached to
+ a network that is capable of Fastlane QoS marking.
+ @result Returns 0 on success, error number otherwise.
+ */
+extern errno_t ifnet_set_fastlane_capable(ifnet_t interface, boolean_t capable);
+
+/*!
+ @function ifnet_get_fastlane_capable
+ @param interface The interface.
+ @param capable On output contains the truth value that the interface
+ is attached ta network that is capable of Fastlane QoS marking.
+ @result Returns 0 on success, error number otherwise.
+ */
+extern errno_t ifnet_get_fastlane_capable(ifnet_t interface, boolean_t *capable);
+
+/*!
+ @function ifnet_get_unsent_bytes
+ @param interface The interface
+ @param unsent_bytes An out parameter that contains unsent bytes for
+ an interface
+ @result Returns 0 on success, error otherwise.
+ */
+extern errno_t ifnet_get_unsent_bytes(ifnet_t interface, int64_t *unsent_bytes);
+
+typedef struct {
+ int32_t buf_interface; /* data to send at interface */
+ int32_t buf_sndbuf; /* data to send at socket buffer */
+} ifnet_buffer_status_t;
+
+/*!
+ @function ifnet_get_buffer_status
+ @param interface The interface
+ @param buf_status An out parameter that contains unsent bytes
+ for an interface
+ @result Returns 0 on success, EINVAL if any of the arguments is
+ NULL, ENXIO if the interface pointer is invalid
+ */
+extern errno_t ifnet_get_buffer_status(const ifnet_t interface,
+ ifnet_buffer_status_t *buf_status);
+
+/*!
+ @function ifnet_normalise_unsent_data
+ @discussion
+ Gathers the unsent bytes on all the interfaces.
+ This data will be reported to NetworkStatistics.
+
+ */
+extern void ifnet_normalise_unsent_data(void);
+
+/*!
+ @function ifnet_touch_lastupdown
+ @discussion Updates the lastupdown value to now.
+ @param interface The interface.
+ @result 0 on success otherwise the errno error.
+ */
+extern errno_t ifnet_touch_lastupdown(ifnet_t interface);
+
+/*!
+ @function ifnet_updown_delta
+ @discussion Retrieves the difference between lastupdown and now.
+ @param interface The interface.
+ @param updown_delta A timeval struct to copy the delta between lastupdown and now.
+ to.
+ */
+extern errno_t ifnet_updown_delta(ifnet_t interface, struct timeval *updown_delta);
+
+#endif /* KERNEL_PRIVATE */
+