API Reference | |
| Receive-Side Scaling (RSS) | |
| Device flags for process-sharing, packet duplication | |
Data Structures | |
| struct | snf_ifaddrs |
| struct | snf_recv_req |
| struct | snf_ring_stats |
Defines | |
| #define | SNF_VERSION_API 0x0002 |
Typedefs | |
| typedef snf_handle * | snf_handle_t |
| opaque snf device handle | |
| typedef snf_ring * | snf_ring_t |
| opaque snf ring handle | |
Functions | |
| int | snf_init (uint16_t api_version) |
| Initialize Sniffer Library with api_version == SNF_VERSION_API. | |
| int | snf_getifaddrs (struct snf_ifaddrs **ifaddrs_o) |
| void | snf_freeifaddrs (struct snf_ifaddrs *ifaddrs) |
| int | snf_open (uint32_t boardnum, int num_rings, const struct snf_rss_params *rss_parms, int64_t dataring_sz, int flags, snf_handle_t *devhandle) |
| Open a device for single or multi-ring operation. | |
| int | snf_start (snf_handle_t devhandle) |
| int | snf_stop (snf_handle_t devhandle) |
| int | snf_close (snf_handle_t devhandle) |
| Close board. | |
| int | snf_ring_open (snf_handle_t devhandle, snf_ring_t *ringh) |
| int | snf_ring_close (snf_ring_t ringh) |
| int | snf_ring_recv (snf_ring_t ringh, int timeout_ms, struct snf_recv_req *recv_req) |
| Receive next packet from a receive ring. | |
| int | snf_ring_getstats (snf_ring_t ringh, struct snf_ring_stats *stats) |
| Get statistics from a receive ring. | |
| #define SNF_VERSION_API 0x0002 |
SNF API version number (16 bits) Least significant byte increases for minor backwards compatible changes in the API. Most significant byte increases for incompatible changes in the API
0x0002: Add nic_bytes_recv counter to stats to help users calculate the amount of bandwidth that is actually going through the NIC port.
| typedef struct snf_handle* snf_handle_t |
opaque snf device handle
Opaque snf handle, allocated at snf_open time when a device can be succesfully opened
| typedef struct snf_ring* snf_ring_t |
opaque snf ring handle
Opaque snf ring handle, allocated at snf_ring_open time when a ring can be succesfully opened
| int snf_close | ( | snf_handle_t | devhandle | ) |
Close board.
This function can be closed once all opened rings (if any) are closed through snf_ring_close. Once a board is determined to be closable, it is implicitly called as if a call had been previously made to snf_stop.
| 0 | Successful. | |
| EBUSY | Some rings are still opened and the board cannot be closed (yet). |
| void snf_freeifaddrs | ( | struct snf_ifaddrs * | ifaddrs | ) |
Free the list of library allocated memory for snf_getifaddrs
| ifaddrs | Pointer to ifaddrs allocated via snf_getifaddrs |
| int snf_getifaddrs | ( | struct snf_ifaddrs ** | ifaddrs_o | ) |
Get a list of Sniffer-capable ethernet devices.
| ifaddrs_o | Library-allocated list of Sniffer-capable devices |
| int snf_init | ( | uint16_t | api_version | ) |
Initialize Sniffer Library with api_version == SNF_VERSION_API.
Initializes the sniffer library.
| api_version | Must always be SNF_VERSION_API |
The library may be safely initialized multiple times, although the api_version shoudl be the same SNF_VERSION_API each time.
| int snf_open | ( | uint32_t | boardnum, | |
| int | num_rings, | |||
| const struct snf_rss_params * | rss_parms, | |||
| int64_t | dataring_sz, | |||
| int | flags, | |||
| snf_handle_t * | devhandle | |||
| ) |
Open a device for single or multi-ring operation.
Opens a board for sniffing and allocates a device handle.
| boardnum | Boards are numbered from 0 to N-1 where 'N' is the number of Myricom ports available on the system. snf_getifaddrs() may be a useful utility to retrieve the board number by interface name or mac address if there are multiple | |
| num_rings | Number of rings to allocate for receive-side scaling feature, which determines how many different threads can open their own ring via snf_ring_open(). If set to 0 or less than zero, default value is used unless SNF_NUM_RINGS is set in the environment. | |
| rss_parms | Points to a user-initialized structure that selects the RSS mechanism to apply to each incoming packet. This parameter is only meaningful if there are more than 1 rings to be opened. By default, if users pass a NULL value, the implementation will select its own mechanism to divide incoming packets across rings. RSS parameters are documented in Receive-Side Scaling (RSS). | |
| dataring_sz | Represents the total amount of memory to be used to store incoming packet data for *all* rings to be opened. If the value is set to 0 or less than 0, the library tries to choose a sensible default unless SNF_DATARING_SIZE is set in the environment. The value can be specified in megabytes (if it is less than 1048576) or is otherwise considered to be in bytes. In either case, the library may slightly adjust the user's request to satisfy alignment requirements (typically 2MB boundaries). | |
| flags | A mask of flags documented in Device flags for process-sharing, packet duplication. | |
| devhandle | Device handle allocated if the call is successful |
| 0 | Successful. the board is opened and a value devhandle is allocated (see remarks) | |
| EBUSY | Device is already opened | |
| EINVAL | Invalid argument passed, most probably num_rings (if not, check syslog) | |
| E2BIG | Driver could not allocate requested dataring_sz (check syslog) | |
| ENOMEM | Either library or driver did not have enough memory to allocate handle descriptors (but not data ring). |
If successful, a call to snf_start is required to the Sniffer-mode NIC to deliver packets to the host, and this call must occur after at least one ring is opened (snf_ring_open).
| int snf_ring_close | ( | snf_ring_t | ringh | ) |
Close a ring
This function is used to inform the underlying device that no further calls to snf_ring_recv will be made. If the device is not subsequently closed (snf_close), all packets that would have been delivered to this ring are dropped. Also, by calling this function, users confirm that all packet processing for packets obtained on this ring via snf_ring_recv is complete.
| ringh | Ring handle |
| 0 | Successful. |
| int snf_ring_getstats | ( | snf_ring_t | ringh, | |
| struct snf_ring_stats * | stats | |||
| ) |
Get statistics from a receive ring.
| ringh | Ring handle | |
| stats | User-provided pointer to a statistics structure snf_ring_stats, filled in by the library. |
| int snf_ring_open | ( | snf_handle_t | devhandle, | |
| snf_ring_t * | ringh | |||
| ) |
Opens a ring from an opened board.
| devhandle | Device handle, obtained from a successful call to snf_ring_open | |
| ringh | Ring handle allocated if the call is successful. |
| 0 | Successful. The ring is opened and ringh contains the ring handle. | |
| EBUSY | Too many rings already opened |
| int snf_ring_recv | ( | snf_ring_t | ringh, | |
| int | timeout_ms, | |||
| struct snf_recv_req * | recv_req | |||
| ) |
Receive next packet from a receive ring.
This function is used to return the next available packet in a receive ring. The function can block indefinitely, for a specific timeout or be used as a non-blocking call with a timeout of 0.
| ringh | Ring handle (from snf_ring_open) | |
| timeout_ms | Receive timeout to control how the function blocks for the next packet. If the value is less than 0, the function can block indefinitely. If the value is 0, the function is guaranteed to never enter a blocking state and returns EAGAIN unless there is a packet waiting. If the value is greater than 0, the caller inidicates a desired wait time in milliseconds. With a non-zero wait time, the function only blocks if there are no outstanding packets. If the timeout expires before a packet can be received, the function returns EAGAIN (and not ETIMEDOUT). In all cases, users should expect that the function may return EINTR as the result of an interrupt. | |
| recv_req | Receive Packet structure, only updated when a the function returns 0 for a successful packet receive (snf_recv_req) |
| 0 | Successful packet delivery, recv_req is updated with packet information. | |
| EINTR | The call was interrupted by a signal handler | |
| EAGAIN | No packets available (only when timeout is >= 0). |
Upon calling the function, the library assumes that the user is done processing the previous packet. The same assumption is made when the ring is closed (snf_ring_close).
| int snf_start | ( | snf_handle_t | devhandle | ) |
| int snf_stop | ( | snf_handle_t | devhandle | ) |
Stop packet capture on a board. This function should be used carefully in multi-process mode as a single stop command stops packet capture on all rings. It is usually best to simply snf_ring_close a ring to stop capture on a ring.
| devhandle | Device handle |
![]()
26 October 2010 Sniffer10G 1.0.2_pcap1.1.1