]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/sys/kern_control.h
xnu-4570.31.3.tar.gz
[apple/xnu.git] / bsd / sys / kern_control.h
index 6ac130dd7066affdf1e3806a6c03c98da226286a..51324ea65260d903d480a97fa555091ef4a02a4a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000-2004, 2012-2014 Apple Inc. All rights reserved.
+ * Copyright (c) 2000-2004, 2012-2016 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
@@ -36,6 +36,9 @@
 
 
 #include <sys/appleapiopts.h>
+#include <sys/_types/_u_char.h>
+#include <sys/_types/_u_int16_t.h>
+#include <sys/_types/_u_int32_t.h>
 
 /*
  * Define Controller event subclass, and associated events.
@@ -187,7 +190,10 @@ struct kctlstat {
        u_int64_t       kcs_send_list_fail __attribute__((aligned(8)));
        u_int64_t       kcs_enqueue_fail __attribute__((aligned(8)));
        u_int64_t       kcs_enqueue_fullsock __attribute__((aligned(8)));
-       
+       u_int64_t       kcs_bad_kctlref __attribute__((aligned(8)));
+       u_int64_t       kcs_tbl_size_too_big __attribute__((aligned(8)));
+       u_int64_t       kcs_enqdata_mb_alloc_fail __attribute__((aligned(8)));
+       u_int64_t       kcs_enqdata_sbappend_fail __attribute__((aligned(8)));
 };
 
 #endif /* PRIVATE */
@@ -411,6 +417,31 @@ typedef void (*ctl_rcvd_func)(kern_ctl_ref kctlref, u_int32_t unit, void *unitin
  */
 typedef errno_t (*ctl_send_list_func)(kern_ctl_ref kctlref, u_int32_t unit, void *unitinfo,
                                        mbuf_t m, int flags);
+
+/*!
+       @typedef ctl_bind_func
+       @discussion The ctl_bind_func is an optional function that allows the client
+               to set up their unitinfo prior to connecting.
+       @param kctlref The control ref for the kernel control the client is
+               binding to.
+       @param sac The address used to connect to this control. The field sc_unit
+               contains the unit number of the kernel control instance the client is
+               binding to. If CTL_FLAG_REG_ID_UNIT was set when the kernel control
+               was registered, sc_unit is the ctl_unit of the kern_ctl_reg structure.
+               If CTL_FLAG_REG_ID_UNIT was not set when the kernel control was
+               registered, sc_unit is the dynamically allocated unit number of
+               the new kernel control instance that is used for this connection.
+       @param unitinfo A placeholder for a pointer to the optional user-defined
+               private data associated with this kernel control instance.  This
+               opaque info will be provided to the user when the rest of the
+               callback routines are executed.  For example, it can be used
+               to pass a pointer to an instance-specific data structure in
+               order for the user to keep track of the states related to this
+               kernel control instance.
+ */
+typedef errno_t (*ctl_bind_func)(kern_ctl_ref kctlref,
+                                                                struct sockaddr_ctl *sac,
+                                                                void **unitinfo);
 #endif /* KERNEL_PRIVATE */
 
 /*!
@@ -468,6 +499,7 @@ struct kern_ctl_reg
 #ifdef KERNEL_PRIVATE
     ctl_rcvd_func              ctl_rcvd;       /* Only valid if CTL_FLAG_REG_EXTENDED is set */
     ctl_send_list_func         ctl_send_list;  /* Only valid if CTL_FLAG_REG_EXTENDED is set */
+       ctl_bind_func           ctl_bind;
 #endif /* KERNEL_PRIVATE */
 };
 
@@ -547,7 +579,7 @@ ctl_enqueuembuf(kern_ctl_ref kctlref, u_int32_t unit, mbuf_t m, u_int32_t flags)
                Not valid if ctl_flags contains CTL_FLAG_REG_SOCK_STREAM.
        @param kctlref The control reference of the kernel control.
        @param unit The unit number of the kernel control instance.
-       @param m An mbuf chain containing the data to send to the client.
+       @param m_list An mbuf chain containing the data to send to the client.
        @param flags Send flags. CTL_DATA_NOWAKEUP is
                the only supported flags.
        @param m_remain A pointer to the list of mbuf packets in the chain that
@@ -560,8 +592,20 @@ errno_t
 ctl_enqueuembuf_list(kern_ctl_ref kctlref, u_int32_t unit, mbuf_t m_list,
        u_int32_t flags, mbuf_t *m_remain);
 
+/*!
+       @function ctl_getenqueuepacketcount
+       @discussion Retrieve the number of packets in the socket
+               receive buffer.
+       @param kctlref The control reference of the kernel control.
+       @param unit The unit number of the kernel control instance.
+       @param pcnt The address where to return the current count. 
+       @result 0 - Success; the packet count is returned to caller.
+               EINVAL - Invalid parameters.
+ */
+errno_t
+ctl_getenqueuepacketcount(kern_ctl_ref kctlref, u_int32_t unit, u_int32_t *pcnt);
 
-#endif
+#endif /* PRIVATE */
 
 /*!
        @function ctl_getenqueuespace
@@ -582,7 +626,7 @@ ctl_getenqueuespace(kern_ctl_ref kctlref, u_int32_t unit, size_t *space);
        low-water mark for the socket receive buffer.
  @param kctlref The control reference of the kernel control.
  @param unit The unit number of the kernel control instance.
- @param u_int32_t The address at which to return the current difference
+ @param difference The address at which to return the current difference
        between the low-water mark for the socket and the number of bytes
        enqueued. 0 indicates that the socket is readable by the client
        (the number of bytes in the buffer is above the low-water mark).
@@ -601,43 +645,11 @@ ctl_getenqueuereadable(kern_ctl_ref kctlref, u_int32_t unit, u_int32_t *differen
  * internal structure maintained for each register controller
  */
 struct ctl_cb;
+struct kctl;
 struct socket;
+struct socket_info;
 
-struct kctl {
-       TAILQ_ENTRY(kctl)               next;           /* controller chain */
-
-       /* controller information provided when registering */
-       char                            name[MAX_KCTL_NAME];    /* unique nke identifier, provided by DTS */
-       u_int32_t                       id;
-       u_int32_t                       reg_unit;
-
-       /* misc communication information */
-       u_int32_t                       flags;          /* support flags */
-       u_int32_t                       recvbufsize;    /* request more than the default buffer size */
-       u_int32_t                       sendbufsize;    /* request more than the default buffer size */
-
-       /* Dispatch functions */
-       ctl_connect_func                connect;        /* Make contact */
-       ctl_disconnect_func             disconnect;     /* Break contact */
-       ctl_send_func                   send;           /* Send data to nke */
-       ctl_send_list_func              send_list;      /* Send list of packets */
-       ctl_setopt_func                 setopt;         /* set kctl configuration */
-       ctl_getopt_func                 getopt;         /* get kctl configuration */
-       ctl_rcvd_func                   rcvd;           /* Notify nke when client reads data */
-
-       TAILQ_HEAD(, ctl_cb)            kcb_head;
-       u_int32_t                       lastunit;
-};
-
-struct ctl_cb {
-       TAILQ_ENTRY(ctl_cb)             next;           /* controller chain */
-       lck_mtx_t                       *mtx;
-       struct socket                   *so;            /* controlling socket */
-       struct kctl                     *kctl;          /* back pointer to controller */
-       void                            *userdata;
-       u_int32_t                       unit;
-       u_int32_t                       usecount;
-};
+void kctl_fill_socketinfo(struct socket *, struct socket_info *);
 
 u_int32_t ctl_id_by_name(const char *name);
 errno_t ctl_name_by_id(u_int32_t id, char *out_name, size_t maxsize);