1. Introduction 1.1. Project/Component Working Name: Python interface to dlpi(7P) 1.2. Name of Document Author/Supplier: Author: Max Zhen 1.3 Date of This Document: 18 August, 2008 4. Technical Description 4.1. Introduction This case introduces the dlpi Python module. It is a wrapper module for dlpi(7P) functions that enables sending/receiving layer2 network packet directly from Python, as well as getting/setting link related configuration. A patch binding is requested. 4.2. Python 'dlpi' module Classification of interfaces provided in this module is 'Committed'. The on-line help clearly shows all interfaces and their counterparts of dlpi functions in this module as below: CLASSES __builtin__.object link exceptions.Exception error class error(exceptions.Exception) | Methods inherited from exceptions.Exception: | | __getitem__(...) | | __init__(...) | | __str__(...) class link(__builtin__.object) | link(linkname, modes) -> link object | | Open linkname in specified mode. | Three modes are supported: PASSIVE, RAW, NATIVE. | And these flags can be bitwise-OR'ed together. | You need sys_net_rawaccess priviledge to open a link. | See dlpi_open(3DLPI). | | Methods defined here: | | bind(...) | bind(sap) -> unsigned int | | Attempts to bind the link to specified SAP, or ANY_SAP. | Returns the SAP that the function actually bound to, which | could be different from the SAP requested. | See dlpi_bind(3DLPI). | | disabmulti(...) | disabmulti(address) -> None | | Disable a specified multicast address on this link. | See dlpi_disabmulti(3DLPI). | | disabnotify(...) | disabnotify(handle) -> argument object, or None | | Disables the notification registration associated with handle. | You should get this handle by calling enabnotify(). | Returns the argument passed in when registering the callback, or None. | See dlpi_disabnotify(3DLPI). | | enabmulti(...) | enabmulti(address) -> None | | Enable a specified multicast address on this link. | See dlpi_enabmulti(3DLPI). | | enabnotify(...) | enabnotify(events, function[, arg]) -> unsigned long | | Enables a notification callback for the set of specified events, | which must be one or more (by a logical OR) events listed as below: | NOTE_LINK_DOWN Notify when link has gone down | NOTE_LINK_UP Notify when link has come up | NOTE_PHYS_ADDR Notify when address changes | NOTE_SDU_SIZE Notify when MTU changes | NOTE_SPEED Notify when speed changes | NOTE_PROMISC_ON_PHYS Notify when DL_PROMISC_PHYS is set | NOTE_PROMISC_OFF_PHYS Notify when DL_PROMISC_PHYS is cleared | Returns a handle for this registration. | See dlpi_enabnotify(3DLPI). | | get_bcastaddr(...) | get_bcastaddr() -> string, or None | | Returns the broadcast address of the link. | Returns None if the broadcast address is empty. | See dlpi_info(3DLPI). | | get_fd(...) | get_fd() -> int | | Returns the integer file descriptor that can be used to directly | operate on the link. | See dlpi_fd(3DLPI). | | get_linkname(...) | get_linkname() -> string | | Returns the name of the link. | See dlpi_linkname(3DLPI). | | get_mactype(...) | get_mactype() -> unsigned char | | Returns MAC type of the link. | See for the list of possible MAC types. | See dlpi_info(3DLPI). | | get_physaddr(...) | get_physaddr(addrtype) -> string | | Addrtype can be any one of the value listed below: | FACT_PHYS_ADDR Factory physical address | CURR_PHYS_ADDR Current physical address | Returns the corresponding physical address of the link. | See dlpi_get_physaddr(3DLPI). | | get_qos_range(...) | get_qos_range() -> | (unsigned int, (int, int), (int, int), (int, int), int) | | Returns (qos type, (trans delay target, trans delay accept), | (min priority, max priority), (min protection, max protection), | residual err). | Unsupported QOS range values are set to UNKNOWN. | See dlpi_info(3DLPI). | | get_qos_select(...) | get_qos_select() -> (unsigned int, int, int, int) | | Returns (qos type, trans delay, priority, residul err). | Unsupported QOS parameters are set to UNKNOWN. | See dlpi_info(3DLPI). | | get_sap(...) | get_sap() -> unsigned int | | Returns the sap bound to this link. | See dlpi_info(3DLPI). | | get_sdu(...) | get_sdu() -> (unsigned int, unsigned int) | | Returns (max sdu, min sdu). | See dlpi_info(3DLPI). | | get_state(...) | get_state() -> unsigned int | | Returns current state of the link (either UNBOUND or IDLE). | See dlpi_info(3DLPI). | | get_timeout(...) | get_timeout() -> int | | Returns current time out value of the link. | See dlpi_info(3DLPI). | | promiscoff(...) | promiscoff(level) -> None | | Disables promiscuous mode for the link at levels: | PROMISC_PHYS Promiscuous mode at the physical level | PROMISC_SAP Promiscuous mode at the SAP level | PROMISC_MULTI Promiscuous mode for all multicast addresses | See dlpi_promiscoff(3DLPI). | | promiscon(...) | promiscon(level) -> None | | Enables promiscuous mode for the link at levels: | PROMISC_PHYS Promiscuous mode at the physical level | PROMISC_SAP Promiscuous mode at the SAP level | PROMISC_MULTI Promiscuous mode for all multicast addresses | See dlpi_promiscon(3DLPI). | | recv(...) | recv(trunksize[, timeout]) -> (string, string) | | Attempts to receive message over this link. | You need to specify the trunk size for the received message. | And you can specify timeout value in milliseconds. | The default timeout value is -1 (wait forever). | Returns (source address, message data). | See dlpi_recv(3DLPI). | | send(...) | send(destaddr, message[, sap, minpri, maxpri]) -> None | | Attempts to send message over this link to SAP on destaddr. | If SAP is not specified, the bound SAP is used | You can also specify priority range (minpri, maxpri). | See dlpi_send(3DLPI). | | set_physaddr(...) | set_physaddr(address) -> None | | Sets the physical address of the link. | See dlpi_set_physaddr(3DLPI). | | set_timeout(...) | set_timeout(timeout) -> None | | Sets time out value of the link (default value: DEF_TIMEOUT). | See dlpi_set_timeout(3DLPI). | | unbind(...) | unbind() -> None | | Attempts to unbind the link from previously bound sap. | See dlpi_unbind(3DLPI). | FUNCTIONS arptype(...) arptype(arptype) -> unsigned int Converts a DLPI MAC type to an ARP hardware type defined in See dlpi_arptype(3DLPI) iftype(...) iftype(iftype) -> unsigned int Converts a DLPI MAC type to a BSD socket interface type defined in See dlpi_iftype(3DLPI) listlink(...) listlink() -> list Returns a list containing link names of all links on the system. mactype(...) mactype(mactype) -> string Returns a string that describes the specified mactype. Valid mac types are defined in . See dlpi_mactype(3DLPI) DATA ANY_SAP CURR_PHYS_ADDR DEF_TIMEOUT FACT_PHYS_ADDR IDLE NATIVE NOTE_LINK_DOWN NOTE_LINK_UP NOTE_PHYS_ADDR NOTE_PROMISC_OFF_PHYS NOTE_PROMISC_ON_PHYS NOTE_SDU_SIZE NOTE_SPEED PASSIVE PROMISC_MULTI PROMISC_PHYS PROMISC_SAP RAW SYSERR UNBOUND UNKNOWN Only one exception will be raise in this module: dlpi.error The accompanying value is: (dlpi_error_number, string), when it is caused by a dlpi specific error, or, (DL_SYSERR, errno, string) when the error is coming from a system call. The dlpi_error_number is the error return value, other than DL_SYSERR, from dlpi_*. The string is used to describe what went wrong during the call. 4.3. References None 6. Resources and Schedule 6.4. Steering Committee requested information 6.4.1. Consolidation C-team Name: JDS 6.5. ARC review type: FastTrack 6.6. ARC Exposure: open