458
|
1 |
diff --git Python-2.6.4/Modules/dlpimodule.c Python-2.6.4/Modules/dlpimodule.c
|
|
2 |
new file mode 100644
|
|
3 |
--- /dev/null
|
|
4 |
+++ Python-2.6.4/Modules/dlpimodule.c
|
|
5 |
@@ -0,0 +1,1205 @@
|
|
6 |
+/*
|
|
7 |
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8 |
+ * of this software and associated documentation files (the "Software"), to
|
|
9 |
+ * deal in the Software without restriction, including without limitation the
|
|
10 |
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
11 |
+ * sell copies of the Software, and to permit persons to whom the Software is
|
|
12 |
+ * furnished to do so, subject to the following conditions:
|
|
13 |
+ *
|
|
14 |
+ * The above copyright notice and this permission notice shall be included in
|
|
15 |
+ * all copies or substantial portions of the Software.
|
|
16 |
+ *
|
|
17 |
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18 |
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19 |
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20 |
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21 |
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
22 |
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
23 |
+ * DEALINGS IN THE SOFTWARE.
|
|
24 |
+ *
|
|
25 |
+ * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
|
|
26 |
+ */
|
|
27 |
+
|
|
28 |
+#include <Python.h>
|
|
29 |
+#include <stdio.h>
|
|
30 |
+#include <libdlpi.h>
|
|
31 |
+
|
|
32 |
+typedef struct {
|
|
33 |
+ PyObject_HEAD
|
|
34 |
+ dlpi_handle_t dlpihdl;
|
|
35 |
+} pylink_t;
|
|
36 |
+
|
|
37 |
+typedef struct {
|
|
38 |
+ PyObject *pyfunc;
|
|
39 |
+ PyObject *pyarg;
|
|
40 |
+} callback_data_t;
|
|
41 |
+
|
|
42 |
+/*
|
|
43 |
+ * dlpi_err: the only exception raised for libdlpi related error.
|
|
44 |
+ * The accompanying value is:
|
|
45 |
+ * (dlpi_error_number, string), when it's a dlpi specific error,
|
|
46 |
+ * or, (DL_SYSERR, errno, string), when it's coming from a system call.
|
|
47 |
+ */
|
|
48 |
+static PyObject *dlpi_err;
|
|
49 |
+
|
|
50 |
+static void
|
|
51 |
+dlpi_raise_exception(int err)
|
|
52 |
+{
|
|
53 |
+ PyObject *e = NULL;
|
|
54 |
+
|
|
55 |
+ if (err == DL_SYSERR) {
|
|
56 |
+ e = Py_BuildValue("(iis)", DL_SYSERR, errno, strerror(errno));
|
|
57 |
+ } else {
|
|
58 |
+ e = Py_BuildValue("(is)", err, dlpi_strerror(err));
|
|
59 |
+ }
|
|
60 |
+ if (e != NULL) {
|
|
61 |
+ PyErr_SetObject(dlpi_err, e);
|
|
62 |
+ Py_DECREF(e);
|
|
63 |
+ }
|
|
64 |
+}
|
|
65 |
+
|
|
66 |
+PyDoc_STRVAR(link_doc,
|
|
67 |
+ "link(linkname[, flags]) -> link object\n"
|
|
68 |
+ "\n"
|
|
69 |
+ "Open linkname with specified flags.\n"
|
|
70 |
+ "Three flags are supported: PASSIVE, RAW, NATIVE.\n"
|
|
71 |
+ "And these flags can be bitwise-OR'ed together(default flag is 0).\n"
|
|
72 |
+ "You need sys_net_rawaccess privilege to open a link.\n"
|
|
73 |
+ "See dlpi_open(3DLPI).\n"
|
|
74 |
+);
|
|
75 |
+static int
|
|
76 |
+link_init(PyObject *self, PyObject *args, PyObject *kwds)
|
|
77 |
+{
|
|
78 |
+ uint_t flags = 0;
|
|
79 |
+ dlpi_handle_t dh;
|
|
80 |
+ char *linkname;
|
|
81 |
+ int rval;
|
|
82 |
+ static char *keywords[] = {"linkname", "flags", NULL};
|
|
83 |
+ pylink_t *link = (pylink_t *)self;
|
|
84 |
+
|
|
85 |
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|I", keywords,
|
|
86 |
+ &linkname, &flags))
|
|
87 |
+ return (-1);
|
|
88 |
+
|
|
89 |
+ if ((rval = dlpi_open(linkname, &dh, flags)) != DLPI_SUCCESS) {
|
|
90 |
+ dlpi_raise_exception(rval);
|
|
91 |
+ return (-1);
|
|
92 |
+ }
|
|
93 |
+
|
|
94 |
+ link->dlpihdl = dh;
|
|
95 |
+
|
|
96 |
+ return (0);
|
|
97 |
+}
|
|
98 |
+
|
|
99 |
+static void
|
|
100 |
+link_dealloc(pylink_t *link)
|
|
101 |
+{
|
|
102 |
+ if (link->dlpihdl != NULL)
|
|
103 |
+ dlpi_close(link->dlpihdl);
|
|
104 |
+ link->ob_type->tp_free((PyObject *)link);
|
|
105 |
+}
|
|
106 |
+
|
|
107 |
+PyDoc_STRVAR(bind_doc,
|
|
108 |
+ "bind(sap) -> unsigned int\n"
|
|
109 |
+ "\n"
|
|
110 |
+ "Attempts to bind the link to specified SAP, or ANY_SAP.\n"
|
|
111 |
+ "Returns the SAP that the function actually bound to, which\n"
|
|
112 |
+ "could be different from the SAP requested.\n"
|
|
113 |
+ "See dlpi_bind(3DLPI).\n"
|
|
114 |
+);
|
|
115 |
+static PyObject *
|
|
116 |
+link_bind(pylink_t *link, PyObject *args, PyObject *kwds)
|
|
117 |
+{
|
|
118 |
+ uint_t sap = 0, boundsap = 0;
|
|
119 |
+ static char *keywords[] = {"sap", NULL};
|
|
120 |
+ int rval;
|
|
121 |
+
|
|
122 |
+ if (link->dlpihdl == NULL) {
|
|
123 |
+ errno = EINVAL;
|
|
124 |
+ dlpi_raise_exception(DL_SYSERR);
|
|
125 |
+ return (NULL);
|
|
126 |
+ }
|
|
127 |
+
|
|
128 |
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "I", keywords, &sap))
|
|
129 |
+ return (NULL);
|
|
130 |
+
|
|
131 |
+ if ((rval = dlpi_bind(link->dlpihdl, sap, &boundsap)) !=
|
|
132 |
+ DLPI_SUCCESS) {
|
|
133 |
+ dlpi_raise_exception(rval);
|
|
134 |
+ return (NULL);
|
|
135 |
+ }
|
|
136 |
+
|
|
137 |
+ return (Py_BuildValue("I", boundsap));
|
|
138 |
+}
|
|
139 |
+
|
|
140 |
+PyDoc_STRVAR(unbind_doc,
|
|
141 |
+ "unbind() -> None\n"
|
|
142 |
+ "\n"
|
|
143 |
+ "Attempts to unbind the link from previously bound sap.\n"
|
|
144 |
+ "See dlpi_unbind(3DLPI).\n"
|
|
145 |
+);
|
|
146 |
+static PyObject *
|
|
147 |
+link_unbind(pylink_t *link)
|
|
148 |
+{
|
|
149 |
+ int rval;
|
|
150 |
+
|
|
151 |
+ if (link->dlpihdl == NULL) {
|
|
152 |
+ errno = EINVAL;
|
|
153 |
+ dlpi_raise_exception(DL_SYSERR);
|
|
154 |
+ return (NULL);
|
|
155 |
+ }
|
|
156 |
+
|
|
157 |
+ if ((rval = dlpi_unbind(link->dlpihdl)) != DLPI_SUCCESS) {
|
|
158 |
+ dlpi_raise_exception(rval);
|
|
159 |
+ return (NULL);
|
|
160 |
+ }
|
|
161 |
+
|
|
162 |
+ Py_INCREF(Py_None);
|
|
163 |
+ return (Py_None);
|
|
164 |
+}
|
|
165 |
+
|
|
166 |
+PyDoc_STRVAR(send_doc,
|
|
167 |
+ "send(destaddr, message[, sap, minpri, maxpri]) -> None\n"
|
|
168 |
+ "\n"
|
|
169 |
+ "Attempts to send message over this link to sap on destaddr.\n"
|
|
170 |
+ "If SAP is not specified, the bound SAP is used\n"
|
|
171 |
+ "You can also specify priority range (minpri, maxpri).\n"
|
|
172 |
+ "See dlpi_send(3DLPI).\n"
|
|
173 |
+);
|
|
174 |
+static PyObject *
|
|
175 |
+link_send(pylink_t *link, PyObject *args, PyObject *kwds)
|
|
176 |
+{
|
|
177 |
+ char *daddr = NULL, *msgbuf = NULL;
|
|
178 |
+ size_t daddrlen = 0, msglen = 0;
|
|
179 |
+ t_scalar_t minpri = DL_QOS_DONT_CARE, maxpri = DL_QOS_DONT_CARE;
|
|
180 |
+ uint_t sap = DLPI_ANY_SAP;
|
|
181 |
+ dlpi_sendinfo_t ds, *dsp = NULL;
|
|
182 |
+ static char *keywords[] =
|
|
183 |
+ {"destaddr", "message", "sap", "minpri", "maxpri", NULL};
|
|
184 |
+ int rval;
|
|
185 |
+
|
|
186 |
+ if (link->dlpihdl == NULL) {
|
|
187 |
+ errno = EINVAL;
|
|
188 |
+ dlpi_raise_exception(DL_SYSERR);
|
|
189 |
+ return (NULL);
|
|
190 |
+ }
|
|
191 |
+
|
|
192 |
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "s#s#|Iii", keywords,
|
|
193 |
+ &daddr, &daddrlen, &msgbuf, &msglen, &sap, &minpri, &maxpri))
|
|
194 |
+ return (NULL);
|
|
195 |
+
|
|
196 |
+ if ((sap != DLPI_ANY_SAP) || (minpri != DL_QOS_DONT_CARE) ||
|
|
197 |
+ (maxpri != DL_QOS_DONT_CARE)) {
|
|
198 |
+ ds.dsi_sap = sap;
|
|
199 |
+ ds.dsi_prio.dl_min = minpri;
|
|
200 |
+ ds.dsi_prio.dl_max = maxpri;
|
|
201 |
+ dsp = &ds;
|
|
202 |
+ }
|
|
203 |
+
|
|
204 |
+ if ((rval = dlpi_send(link->dlpihdl, daddr, daddrlen,
|
|
205 |
+ msgbuf, msglen, dsp)) != DLPI_SUCCESS) {
|
|
206 |
+ dlpi_raise_exception(rval);
|
|
207 |
+ return (NULL);
|
|
208 |
+ }
|
|
209 |
+
|
|
210 |
+ Py_INCREF(Py_None);
|
|
211 |
+ return (Py_None);
|
|
212 |
+}
|
|
213 |
+
|
|
214 |
+PyDoc_STRVAR(recv_doc,
|
|
215 |
+ "recv(msglen[, timeout]) -> (string, string), or (None, None)\n"
|
|
216 |
+ "\n"
|
|
217 |
+ "Attempts to receive message over this link.\n"
|
|
218 |
+ "You need to specify the message length for the received message.\n"
|
|
219 |
+ "And you can specify timeout value in milliseconds.\n"
|
|
220 |
+ "The default timeout value is -1 (wait forever).\n"
|
|
221 |
+ "Returns (source address, message data), or (None, None) when error occurs.\n"
|
|
222 |
+ "See dlpi_recv(3DLPI).\n"
|
|
223 |
+);
|
|
224 |
+static PyObject *
|
|
225 |
+link_recv(pylink_t *link, PyObject *args, PyObject *kwds)
|
|
226 |
+{
|
|
227 |
+ PyObject *obj;
|
|
228 |
+ char *saddr = NULL, *msgbuf = NULL;
|
|
229 |
+ size_t saddrlen = 0, msglen = 0, *saddrlenp = NULL, *msglenp = NULL;
|
|
230 |
+ int msec = -1; /* block until receive data */
|
|
231 |
+ static char *keywords[] = {"msglen", "timeout", NULL};
|
|
232 |
+ int rval;
|
|
233 |
+
|
|
234 |
+ if (link->dlpihdl == NULL) {
|
|
235 |
+ errno = EINVAL;
|
|
236 |
+ dlpi_raise_exception(DL_SYSERR);
|
|
237 |
+ return (NULL);
|
|
238 |
+ }
|
|
239 |
+
|
|
240 |
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "k|i",
|
|
241 |
+ keywords, &msglen, &msec))
|
|
242 |
+ return (NULL);
|
|
243 |
+
|
|
244 |
+ if (msglen > 0) {
|
|
245 |
+ msgbuf = malloc(msglen);
|
|
246 |
+ if (msgbuf == NULL) {
|
|
247 |
+ dlpi_raise_exception(DL_SYSERR);
|
|
248 |
+ return (NULL);
|
|
249 |
+ }
|
|
250 |
+ saddrlen = DLPI_PHYSADDR_MAX;
|
|
251 |
+ saddr = malloc(saddrlen);
|
|
252 |
+ if (saddr == NULL) {
|
|
253 |
+ dlpi_raise_exception(DL_SYSERR);
|
|
254 |
+ free(msgbuf);
|
|
255 |
+ return (NULL);
|
|
256 |
+ }
|
|
257 |
+ msglenp = &msglen;
|
|
258 |
+ saddrlenp = &saddrlen;
|
|
259 |
+ }
|
|
260 |
+
|
|
261 |
+ if ((rval = dlpi_recv(link->dlpihdl, saddr, saddrlenp, msgbuf,
|
|
262 |
+ msglenp, msec, NULL)) != DLPI_SUCCESS) {
|
|
263 |
+ if (msgbuf != NULL)
|
|
264 |
+ free(msgbuf);
|
|
265 |
+ if (saddr != NULL)
|
|
266 |
+ free(saddr);
|
|
267 |
+ dlpi_raise_exception(rval);
|
|
268 |
+ return (NULL);
|
|
269 |
+ }
|
|
270 |
+
|
|
271 |
+ obj = Py_BuildValue("s#s#", saddr, saddrlen, msgbuf, msglen);
|
|
272 |
+ if (msgbuf != NULL)
|
|
273 |
+ free(msgbuf);
|
|
274 |
+ if (saddr != NULL)
|
|
275 |
+ free(saddr);
|
|
276 |
+ return (obj);
|
|
277 |
+}
|
|
278 |
+
|
|
279 |
+PyDoc_STRVAR(disabmulti_doc,
|
|
280 |
+ "disabmulti(address) -> None\n"
|
|
281 |
+ "\n"
|
|
282 |
+ "Disable a specified multicast address on this link.\n"
|
|
283 |
+ "See dlpi_disabmulti(3DLPI).\n"
|
|
284 |
+);
|
|
285 |
+static PyObject *
|
|
286 |
+link_disabmulti(pylink_t *link, PyObject *args, PyObject *kwds)
|
|
287 |
+{
|
|
288 |
+ char *addr = NULL;
|
|
289 |
+ size_t addrlen = 0;
|
|
290 |
+ static char *keywords[] = {"address", NULL};
|
|
291 |
+ int rval;
|
|
292 |
+
|
|
293 |
+ if (link->dlpihdl == NULL) {
|
|
294 |
+ errno = EINVAL;
|
|
295 |
+ dlpi_raise_exception(DL_SYSERR);
|
|
296 |
+ return (NULL);
|
|
297 |
+ }
|
|
298 |
+
|
|
299 |
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "s#", keywords,
|
|
300 |
+ &addr, &addrlen))
|
|
301 |
+ return (NULL);
|
|
302 |
+
|
|
303 |
+ if ((addrlen == 0) || (addrlen > DLPI_PHYSADDR_MAX)) {
|
|
304 |
+ errno = EINVAL;
|
|
305 |
+ dlpi_raise_exception(DL_SYSERR);
|
|
306 |
+ return (NULL);
|
|
307 |
+ }
|
|
308 |
+
|
|
309 |
+ if ((rval = dlpi_disabmulti(link->dlpihdl, addr, addrlen)) !=
|
|
310 |
+ DLPI_SUCCESS) {
|
|
311 |
+ dlpi_raise_exception(rval);
|
|
312 |
+ return (NULL);
|
|
313 |
+ }
|
|
314 |
+
|
|
315 |
+ Py_INCREF(Py_None);
|
|
316 |
+ return (Py_None);
|
|
317 |
+}
|
|
318 |
+
|
|
319 |
+PyDoc_STRVAR(enabmulti_doc,
|
|
320 |
+ "enabmulti(address) -> None\n"
|
|
321 |
+ "\n"
|
|
322 |
+ "Enable a specified multicast address on this link.\n"
|
|
323 |
+ "See dlpi_enabmulti(3DLPI).\n"
|
|
324 |
+);
|
|
325 |
+static PyObject *
|
|
326 |
+link_enabmulti(pylink_t *link, PyObject *args, PyObject *kwds)
|
|
327 |
+{
|
|
328 |
+ char *addr = NULL;
|
|
329 |
+ size_t addrlen = 0;
|
|
330 |
+ static char *keywords[] = {"address", NULL};
|
|
331 |
+ int rval;
|
|
332 |
+
|
|
333 |
+ if (link->dlpihdl == NULL) {
|
|
334 |
+ errno = EINVAL;
|
|
335 |
+ dlpi_raise_exception(DL_SYSERR);
|
|
336 |
+ return (NULL);
|
|
337 |
+ }
|
|
338 |
+
|
|
339 |
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "s#", keywords,
|
|
340 |
+ &addr, &addrlen))
|
|
341 |
+ return (NULL);
|
|
342 |
+
|
|
343 |
+ if ((addrlen == 0) || (addrlen > DLPI_PHYSADDR_MAX)) {
|
|
344 |
+ errno = EINVAL;
|
|
345 |
+ dlpi_raise_exception(DL_SYSERR);
|
|
346 |
+ return (NULL);
|
|
347 |
+ }
|
|
348 |
+
|
|
349 |
+ if ((rval = dlpi_enabmulti(link->dlpihdl, addr, addrlen)) !=
|
|
350 |
+ DLPI_SUCCESS) {
|
|
351 |
+ dlpi_raise_exception(rval);
|
|
352 |
+ return (NULL);
|
|
353 |
+ }
|
|
354 |
+
|
|
355 |
+ Py_INCREF(Py_None);
|
|
356 |
+ return (Py_None);
|
|
357 |
+}
|
|
358 |
+
|
|
359 |
+static void
|
|
360 |
+dlpi_callback(dlpi_handle_t hdl, dlpi_notifyinfo_t *ni, void *arg)
|
|
361 |
+{
|
|
362 |
+ callback_data_t *cd = (callback_data_t *)arg;
|
|
363 |
+ PyObject *arglist, *result;
|
|
364 |
+
|
|
365 |
+ switch (ni->dni_note) {
|
|
366 |
+ case DL_NOTE_SPEED:
|
|
367 |
+ arglist = Py_BuildValue("(OII)",
|
|
368 |
+ cd->pyarg, ni->dni_note, ni->dni_speed);
|
|
369 |
+ break;
|
|
370 |
+ case DL_NOTE_SDU_SIZE:
|
|
371 |
+ arglist = Py_BuildValue("(OII)",
|
|
372 |
+ cd->pyarg, ni->dni_note, ni->dni_size);
|
|
373 |
+ break;
|
|
374 |
+ case DL_NOTE_PHYS_ADDR:
|
|
375 |
+ arglist = Py_BuildValue("(OIs#)",
|
|
376 |
+ cd->pyarg, ni->dni_note, ni->dni_physaddr,
|
|
377 |
+ ni->dni_physaddrlen);
|
|
378 |
+ break;
|
|
379 |
+ default:
|
|
380 |
+ arglist = Py_BuildValue("(OIO)", cd->pyarg, ni->dni_note,
|
|
381 |
+ Py_None);
|
|
382 |
+ }
|
|
383 |
+
|
|
384 |
+ result = PyEval_CallObject(cd->pyfunc, arglist);
|
|
385 |
+ Py_DECREF(arglist);
|
|
386 |
+ if (result == NULL) {
|
|
387 |
+ PyErr_Clear(); /* cannot raise error */
|
|
388 |
+ }
|
|
389 |
+ Py_DECREF(result);
|
|
390 |
+ Py_DECREF(cd->pyfunc);
|
|
391 |
+ Py_XDECREF(cd->pyarg);
|
|
392 |
+ free(cd);
|
|
393 |
+}
|
|
394 |
+
|
|
395 |
+PyDoc_STRVAR(enabnotify_doc,
|
|
396 |
+ "enabnotify(events, function[, arg]) -> unsigned long\n"
|
|
397 |
+ "\n"
|
|
398 |
+ "Enables a notification callback for the set of specified events,\n"
|
|
399 |
+ "which must be one or more (by a logical OR) events listed as below:\n"
|
|
400 |
+ "NOTE_LINK_DOWN Notify when link has gone down\n"
|
|
401 |
+ "NOTE_LINK_UP Notify when link has come up\n"
|
|
402 |
+ "NOTE_PHYS_ADDR Notify when address changes\n"
|
|
403 |
+ "NOTE_SDU_SIZE Notify when MTU changes\n"
|
|
404 |
+ "NOTE_SPEED Notify when speed changes\n"
|
|
405 |
+ "NOTE_PROMISC_ON_PHYS Notify when PROMISC_PHYS is set\n"
|
|
406 |
+ "NOTE_PROMISC_OFF_PHYS Notify when PROMISC_PHYS is cleared\n"
|
|
407 |
+ "Returns a handle for this registration.\n"
|
|
408 |
+ "See dlpi_enabnotify(3DLPI).\n"
|
|
409 |
+);
|
|
410 |
+static PyObject *
|
|
411 |
+link_enabnotify(pylink_t *link, PyObject *args, PyObject *kwds)
|
|
412 |
+{
|
|
413 |
+ PyObject *func = NULL, *arg = NULL;
|
|
414 |
+ callback_data_t *cd;
|
|
415 |
+ uint_t notes = 0;
|
|
416 |
+ static char *keywords[] = {"events", "function", "arg", NULL};
|
|
417 |
+ dlpi_notifyid_t id;
|
|
418 |
+ int rval;
|
|
419 |
+
|
|
420 |
+ if (link->dlpihdl == NULL) {
|
|
421 |
+ errno = EINVAL;
|
|
422 |
+ dlpi_raise_exception(DL_SYSERR);
|
|
423 |
+ return (NULL);
|
|
424 |
+ }
|
|
425 |
+
|
|
426 |
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "IO|O",
|
|
427 |
+ keywords, ¬es, &func, &arg))
|
|
428 |
+ return (NULL);
|
|
429 |
+
|
|
430 |
+ if (!PyCallable_Check(func)) {
|
|
431 |
+ errno = EINVAL;
|
|
432 |
+ dlpi_raise_exception(DL_SYSERR);
|
|
433 |
+ return (NULL);
|
|
434 |
+ }
|
|
435 |
+
|
|
436 |
+ cd = malloc(sizeof(callback_data_t));
|
|
437 |
+ if (cd == NULL) {
|
|
438 |
+ dlpi_raise_exception(DL_SYSERR);
|
|
439 |
+ return (NULL);
|
|
440 |
+ }
|
|
441 |
+ Py_INCREF(func);
|
|
442 |
+ Py_XINCREF(arg);
|
|
443 |
+ cd->pyfunc = func;
|
|
444 |
+ cd->pyarg = arg;
|
|
445 |
+
|
|
446 |
+ if ((rval = dlpi_enabnotify(link->dlpihdl, notes, dlpi_callback,
|
|
447 |
+ cd, &id)) != DLPI_SUCCESS) {
|
|
448 |
+ free(cd);
|
|
449 |
+ Py_DECREF(func);
|
|
450 |
+ Py_XDECREF(arg);
|
|
451 |
+ dlpi_raise_exception(rval);
|
|
452 |
+ return (NULL);
|
|
453 |
+ }
|
|
454 |
+
|
|
455 |
+ return (Py_BuildValue("k", id));
|
|
456 |
+}
|
|
457 |
+
|
|
458 |
+PyDoc_STRVAR(disabnotify_doc,
|
|
459 |
+ "disabnotify(handle) -> argument object, or None\n"
|
|
460 |
+ "\n"
|
|
461 |
+ "Disables the notification registration associated with handle.\n"
|
|
462 |
+ "You should get this handle by calling enabnotify().\n"
|
|
463 |
+ "Returns the argument passed in when registering the callback, or None.\n"
|
|
464 |
+ "See dlpi_disabnotify(3DLPI).\n"
|
|
465 |
+);
|
|
466 |
+static PyObject *
|
|
467 |
+link_disabnotify(pylink_t *link, PyObject *args, PyObject *kwds)
|
|
468 |
+{
|
|
469 |
+ dlpi_notifyid_t id;
|
|
470 |
+ callback_data_t *arg;
|
|
471 |
+ PyObject *pyargsaved;
|
|
472 |
+ static char *keywords[] = {"handle", NULL};
|
|
473 |
+ int rval;
|
|
474 |
+
|
|
475 |
+ if (link->dlpihdl == NULL) {
|
|
476 |
+ errno = EINVAL;
|
|
477 |
+ dlpi_raise_exception(DL_SYSERR);
|
|
478 |
+ return (NULL);
|
|
479 |
+ }
|
|
480 |
+
|
|
481 |
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "k", keywords, &id))
|
|
482 |
+ return (NULL);
|
|
483 |
+
|
|
484 |
+ if ((rval = dlpi_disabnotify(link->dlpihdl, id, (void **)&arg)) !=
|
|
485 |
+ DLPI_SUCCESS) {
|
|
486 |
+ dlpi_raise_exception(rval);
|
|
487 |
+ return (NULL);
|
|
488 |
+ }
|
|
489 |
+
|
|
490 |
+ /* clean up */
|
|
491 |
+ pyargsaved = arg->pyarg;
|
|
492 |
+ Py_XINCREF(pyargsaved);
|
|
493 |
+ Py_XDECREF(arg->pyarg);
|
|
494 |
+ Py_DECREF(arg->pyfunc);
|
|
495 |
+ free(arg);
|
|
496 |
+
|
|
497 |
+ if (pyargsaved != NULL)
|
|
498 |
+ return (pyargsaved);
|
|
499 |
+
|
|
500 |
+ Py_INCREF(Py_None);
|
|
501 |
+ return (Py_None);
|
|
502 |
+}
|
|
503 |
+
|
|
504 |
+PyDoc_STRVAR(get_sap_doc,
|
|
505 |
+ "get_sap() -> unsigned int\n"
|
|
506 |
+ "\n"
|
|
507 |
+ "Returns the sap bound to this link.\n"
|
|
508 |
+ "See dlpi_info(3DLPI).\n"
|
|
509 |
+);
|
|
510 |
+static PyObject *
|
|
511 |
+link_get_sap(pylink_t *link)
|
|
512 |
+{
|
|
513 |
+ dlpi_info_t info;
|
|
514 |
+ int rval;
|
|
515 |
+
|
|
516 |
+ if (link->dlpihdl == NULL) {
|
|
517 |
+ errno = EINVAL;
|
|
518 |
+ dlpi_raise_exception(DL_SYSERR);
|
|
519 |
+ return (NULL);
|
|
520 |
+ }
|
|
521 |
+
|
|
522 |
+ if ((rval = dlpi_info(link->dlpihdl, &info, 0)) !=
|
|
523 |
+ DLPI_SUCCESS) {
|
|
524 |
+ dlpi_raise_exception(rval);
|
|
525 |
+ return (NULL);
|
|
526 |
+ }
|
|
527 |
+
|
|
528 |
+ return (Py_BuildValue("I", info.di_sap));
|
|
529 |
+}
|
|
530 |
+
|
|
531 |
+PyDoc_STRVAR(get_fd_doc,
|
|
532 |
+ "get_fd() -> int\n"
|
|
533 |
+ "\n"
|
|
534 |
+ "Returns the integer file descriptor that can be used to directly\n"
|
|
535 |
+ "operate on the link.\n"
|
|
536 |
+ "See dlpi_fd(3DLPI).\n"
|
|
537 |
+);
|
|
538 |
+static PyObject *
|
|
539 |
+link_get_fd(pylink_t *link)
|
|
540 |
+{
|
|
541 |
+ int fd;
|
|
542 |
+
|
|
543 |
+ if (link->dlpihdl == NULL) {
|
|
544 |
+ errno = EINVAL;
|
|
545 |
+ dlpi_raise_exception(DL_SYSERR);
|
|
546 |
+ return (NULL);
|
|
547 |
+ }
|
|
548 |
+
|
|
549 |
+ if ((fd = dlpi_fd(link->dlpihdl)) == -1) {
|
|
550 |
+ dlpi_raise_exception(DL_SYSERR);
|
|
551 |
+ return (NULL);
|
|
552 |
+ }
|
|
553 |
+
|
|
554 |
+ return (Py_BuildValue("i", fd));
|
|
555 |
+}
|
|
556 |
+
|
|
557 |
+PyDoc_STRVAR(get_linkname_doc,
|
|
558 |
+ "get_linkname() -> string\n"
|
|
559 |
+ "\n"
|
|
560 |
+ "Returns the name of the link.\n"
|
|
561 |
+ "See dlpi_linkname(3DLPI).\n"
|
|
562 |
+);
|
|
563 |
+static PyObject *
|
|
564 |
+link_get_linkname(pylink_t *link)
|
|
565 |
+{
|
|
566 |
+ const char *name = NULL;
|
|
567 |
+
|
|
568 |
+ if (link->dlpihdl == NULL) {
|
|
569 |
+ errno = EINVAL;
|
|
570 |
+ dlpi_raise_exception(DL_SYSERR);
|
|
571 |
+ return (NULL);
|
|
572 |
+ }
|
|
573 |
+
|
|
574 |
+ if ((name = dlpi_linkname(link->dlpihdl)) == NULL) {
|
|
575 |
+ dlpi_raise_exception(DL_SYSERR);
|
|
576 |
+ return (NULL);
|
|
577 |
+ }
|
|
578 |
+
|
|
579 |
+ return (Py_BuildValue("s", name));
|
|
580 |
+}
|
|
581 |
+
|
|
582 |
+PyDoc_STRVAR(get_bcastaddr_doc,
|
|
583 |
+ "get_bcastaddr() -> string, or None\n"
|
|
584 |
+ "\n"
|
|
585 |
+ "Returns the broadcast address of the link.\n"
|
|
586 |
+ "Returns None if the broadcast address is empty.\n"
|
|
587 |
+ "See dlpi_info(3DLPI).\n"
|
|
588 |
+);
|
|
589 |
+static PyObject *
|
|
590 |
+link_get_bcastaddr(pylink_t *link)
|
|
591 |
+{
|
|
592 |
+ char *addr[DLPI_PHYSADDR_MAX];
|
|
593 |
+ size_t addrlen = 0;
|
|
594 |
+ dlpi_info_t info;
|
|
595 |
+ int rval;
|
|
596 |
+
|
|
597 |
+ if (link->dlpihdl == NULL) {
|
|
598 |
+ errno = EINVAL;
|
|
599 |
+ dlpi_raise_exception(DL_SYSERR);
|
|
600 |
+ return (NULL);
|
|
601 |
+ }
|
|
602 |
+
|
|
603 |
+ if ((rval = dlpi_info(link->dlpihdl, &info, 0)) !=
|
|
604 |
+ DLPI_SUCCESS) {
|
|
605 |
+ dlpi_raise_exception(rval);
|
|
606 |
+ return (NULL);
|
|
607 |
+ }
|
|
608 |
+
|
|
609 |
+ if (info.di_bcastaddrlen == 0) {
|
|
610 |
+ Py_INCREF(Py_None);
|
|
611 |
+ return (Py_None);
|
|
612 |
+ }
|
|
613 |
+
|
|
614 |
+ return (Py_BuildValue("s#", info.di_bcastaddr, info.di_bcastaddrlen));
|
|
615 |
+}
|
|
616 |
+
|
|
617 |
+PyDoc_STRVAR(get_physaddr_doc,
|
|
618 |
+ "get_physaddr(addrtype) -> string, or None\n"
|
|
619 |
+ "\n"
|
|
620 |
+ "Addrtype can be any one of the value listed below:\n"
|
|
621 |
+ "FACT_PHYS_ADDR Factory physical address\n"
|
|
622 |
+ "CURR_PHYS_ADDR Current physical address\n"
|
|
623 |
+ "Returns the corresponding physical address of the link.\n"
|
|
624 |
+ "See dlpi_get_physaddr(3DLPI).\n"
|
|
625 |
+);
|
|
626 |
+static PyObject *
|
|
627 |
+link_get_physaddr(pylink_t *link, PyObject *args, PyObject *kwds)
|
|
628 |
+{
|
|
629 |
+ char *addr[DLPI_PHYSADDR_MAX];
|
|
630 |
+ size_t addrlen = DLPI_PHYSADDR_MAX;
|
|
631 |
+ static char *keywords[] = {"addrtype", NULL};
|
|
632 |
+ uint_t type;
|
|
633 |
+ int rval;
|
|
634 |
+
|
|
635 |
+ if (link->dlpihdl == NULL) {
|
|
636 |
+ errno = EINVAL;
|
|
637 |
+ dlpi_raise_exception(DL_SYSERR);
|
|
638 |
+ return (NULL);
|
|
639 |
+ }
|
|
640 |
+
|
|
641 |
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "I", keywords, &type))
|
|
642 |
+ return (NULL);
|
|
643 |
+
|
|
644 |
+ if ((rval = dlpi_get_physaddr(link->dlpihdl, type, addr, &addrlen)) !=
|
|
645 |
+ DLPI_SUCCESS) {
|
|
646 |
+ dlpi_raise_exception(rval);
|
|
647 |
+ return (NULL);
|
|
648 |
+ }
|
|
649 |
+
|
|
650 |
+ return (Py_BuildValue("s#", addr, addrlen));
|
|
651 |
+}
|
|
652 |
+
|
|
653 |
+PyDoc_STRVAR(set_physaddr_doc,
|
|
654 |
+ "set_physaddr(address) -> None\n"
|
|
655 |
+ "\n"
|
|
656 |
+ "Sets the physical address of the link.\n"
|
|
657 |
+ "See dlpi_set_physaddr(3DLPI).\n"
|
|
658 |
+);
|
|
659 |
+static PyObject *
|
|
660 |
+link_set_physaddr(pylink_t *link, PyObject *args, PyObject *kwds)
|
|
661 |
+{
|
|
662 |
+ char *addr = NULL;
|
|
663 |
+ size_t addrlen = 0;
|
|
664 |
+ static char *keywords[] = {"address", NULL};
|
|
665 |
+ int rval;
|
|
666 |
+
|
|
667 |
+ if (link->dlpihdl == NULL) {
|
|
668 |
+ errno = EINVAL;
|
|
669 |
+ dlpi_raise_exception(DL_SYSERR);
|
|
670 |
+ return (NULL);
|
|
671 |
+ }
|
|
672 |
+
|
|
673 |
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "s#", keywords,
|
|
674 |
+ &addr, &addrlen))
|
|
675 |
+ return (NULL);
|
|
676 |
+
|
|
677 |
+ if ((rval = dlpi_set_physaddr(link->dlpihdl, DL_CURR_PHYS_ADDR,
|
|
678 |
+ addr, addrlen)) != DLPI_SUCCESS) {
|
|
679 |
+ dlpi_raise_exception(rval);
|
|
680 |
+ return (NULL);
|
|
681 |
+ }
|
|
682 |
+
|
|
683 |
+ Py_INCREF(Py_None);
|
|
684 |
+ return (Py_None);
|
|
685 |
+}
|
|
686 |
+
|
|
687 |
+PyDoc_STRVAR(promiscon_doc,
|
|
688 |
+ "promiscon([level]) -> None\n"
|
|
689 |
+ "\n"
|
|
690 |
+ "Enables promiscuous mode for the link at levels:\n"
|
|
691 |
+ "PROMISC_PHYS Promiscuous mode at the physical level(default)\n"
|
|
692 |
+ "PROMISC_SAP Promiscuous mode at the SAP level\n"
|
|
693 |
+ "PROMISC_MULTI Promiscuous mode for all multicast addresses\n"
|
|
694 |
+ "See dlpi_promiscon(3DLPI).\n"
|
|
695 |
+);
|
|
696 |
+static PyObject *
|
|
697 |
+link_promiscon(pylink_t *link, PyObject *args, PyObject *kwds)
|
|
698 |
+{
|
|
699 |
+ uint_t level = DL_PROMISC_PHYS;
|
|
700 |
+ static char *keywords[] = {"level", NULL};
|
|
701 |
+ int rval;
|
|
702 |
+
|
|
703 |
+ if (link->dlpihdl == NULL) {
|
|
704 |
+ errno = EINVAL;
|
|
705 |
+ dlpi_raise_exception(DL_SYSERR);
|
|
706 |
+ return (NULL);
|
|
707 |
+ }
|
|
708 |
+
|
|
709 |
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|I", keywords, &level))
|
|
710 |
+ return (NULL);
|
|
711 |
+
|
|
712 |
+ if ((rval = dlpi_promiscon(link->dlpihdl, level)) != DLPI_SUCCESS) {
|
|
713 |
+ dlpi_raise_exception(rval);
|
|
714 |
+ return (NULL);
|
|
715 |
+ }
|
|
716 |
+
|
|
717 |
+ Py_INCREF(Py_None);
|
|
718 |
+ return (Py_None);
|
|
719 |
+}
|
|
720 |
+
|
|
721 |
+PyDoc_STRVAR(promiscoff_doc,
|
|
722 |
+ "promiscoff([level]) -> None\n"
|
|
723 |
+ "\n"
|
|
724 |
+ "Disables promiscuous mode for the link at levels:\n"
|
|
725 |
+ "PROMISC_PHYS Promiscuous mode at the physical level(default)\n"
|
|
726 |
+ "PROMISC_SAP Promiscuous mode at the SAP level\n"
|
|
727 |
+ "PROMISC_MULTI Promiscuous mode for all multicast addresses\n"
|
|
728 |
+ "See dlpi_promiscoff(3DLPI).\n"
|
|
729 |
+);
|
|
730 |
+static PyObject *
|
|
731 |
+link_promiscoff(pylink_t *link, PyObject *args, PyObject *kwds)
|
|
732 |
+{
|
|
733 |
+ uint_t level = DL_PROMISC_PHYS;
|
|
734 |
+ static char *keywords[] = {"level", NULL};
|
|
735 |
+ int rval;
|
|
736 |
+
|
|
737 |
+ if (link->dlpihdl == NULL) {
|
|
738 |
+ errno = EINVAL;
|
|
739 |
+ dlpi_raise_exception(DL_SYSERR);
|
|
740 |
+ return (NULL);
|
|
741 |
+ }
|
|
742 |
+
|
|
743 |
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|I", keywords, &level))
|
|
744 |
+ return (NULL);
|
|
745 |
+
|
|
746 |
+ if ((rval = dlpi_promiscoff(link->dlpihdl, level)) != DLPI_SUCCESS) {
|
|
747 |
+ dlpi_raise_exception(rval);
|
|
748 |
+ return (NULL);
|
|
749 |
+ }
|
|
750 |
+
|
|
751 |
+ Py_INCREF(Py_None);
|
|
752 |
+ return (Py_None);
|
|
753 |
+}
|
|
754 |
+
|
|
755 |
+PyDoc_STRVAR(get_timeout_doc,
|
|
756 |
+ "get_timeout() -> int\n"
|
|
757 |
+ "\n"
|
|
758 |
+ "Returns current time out value of the link.\n"
|
|
759 |
+ "See dlpi_info(3DLPI).\n"
|
|
760 |
+);
|
|
761 |
+static PyObject *
|
|
762 |
+link_get_timeout(pylink_t *link)
|
|
763 |
+{
|
|
764 |
+ dlpi_info_t info;
|
|
765 |
+ int rval;
|
|
766 |
+
|
|
767 |
+ if (link->dlpihdl == NULL) {
|
|
768 |
+ errno = EINVAL;
|
|
769 |
+ dlpi_raise_exception(DL_SYSERR);
|
|
770 |
+ return (NULL);
|
|
771 |
+ }
|
|
772 |
+
|
|
773 |
+ if ((rval = dlpi_info(link->dlpihdl, &info, 0)) !=
|
|
774 |
+ DLPI_SUCCESS) {
|
|
775 |
+ dlpi_raise_exception(rval);
|
|
776 |
+ return (NULL);
|
|
777 |
+ }
|
|
778 |
+
|
|
779 |
+ return (Py_BuildValue("i", info.di_timeout));
|
|
780 |
+}
|
|
781 |
+
|
|
782 |
+PyDoc_STRVAR(get_mactype_doc,
|
|
783 |
+ "get_mactype() -> unsigned char\n"
|
|
784 |
+ "\n"
|
|
785 |
+ "Returns MAC type of the link.\n"
|
|
786 |
+ "See <sys/dlpi.h> for the list of possible MAC types.\n"
|
|
787 |
+ "See dlpi_info(3DLPI).\n"
|
|
788 |
+);
|
|
789 |
+static PyObject *
|
|
790 |
+link_get_mactype(pylink_t *link)
|
|
791 |
+{
|
|
792 |
+ dlpi_info_t info;
|
|
793 |
+ int rval;
|
|
794 |
+
|
|
795 |
+ if (link->dlpihdl == NULL) {
|
|
796 |
+ errno = EINVAL;
|
|
797 |
+ dlpi_raise_exception(DL_SYSERR);
|
|
798 |
+ return (NULL);
|
|
799 |
+ }
|
|
800 |
+
|
|
801 |
+ if ((rval = dlpi_info(link->dlpihdl, &info, 0)) !=
|
|
802 |
+ DLPI_SUCCESS) {
|
|
803 |
+ dlpi_raise_exception(rval);
|
|
804 |
+ return (NULL);
|
|
805 |
+ }
|
|
806 |
+
|
|
807 |
+ return (Py_BuildValue("B", info.di_mactype));
|
|
808 |
+}
|
|
809 |
+
|
|
810 |
+PyDoc_STRVAR(set_timeout_doc,
|
|
811 |
+ "set_timeout(timeout) -> None\n"
|
|
812 |
+ "\n"
|
|
813 |
+ "Sets time out value of the link (default value: DEF_TIMEOUT).\n"
|
|
814 |
+ "See dlpi_set_timeout(3DLPI).\n"
|
|
815 |
+);
|
|
816 |
+static PyObject *
|
|
817 |
+link_set_timeout(pylink_t *link, PyObject *args, PyObject *kwds)
|
|
818 |
+{
|
|
819 |
+ int timeout = DLPI_DEF_TIMEOUT;
|
|
820 |
+ static char *keywords[] = {"timeout", NULL};
|
|
821 |
+ int rval;
|
|
822 |
+
|
|
823 |
+ if (link->dlpihdl == NULL) {
|
|
824 |
+ errno = EINVAL;
|
|
825 |
+ dlpi_raise_exception(DL_SYSERR);
|
|
826 |
+ return (NULL);
|
|
827 |
+ }
|
|
828 |
+
|
|
829 |
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "i", keywords, &timeout))
|
|
830 |
+ return (NULL);
|
|
831 |
+
|
|
832 |
+ if ((rval = dlpi_set_timeout(link->dlpihdl, timeout)) != DLPI_SUCCESS) {
|
|
833 |
+ dlpi_raise_exception(rval);
|
|
834 |
+ return (NULL);
|
|
835 |
+ }
|
|
836 |
+
|
|
837 |
+ Py_INCREF(Py_None);
|
|
838 |
+ return (Py_None);
|
|
839 |
+}
|
|
840 |
+
|
|
841 |
+PyDoc_STRVAR(get_sdu_doc,
|
|
842 |
+ "get_sdu() -> (unsigned int, unsigned int)\n"
|
|
843 |
+ "\n"
|
|
844 |
+ "Returns (min sdu, max sdu).\n"
|
|
845 |
+ "See dlpi_info(3DLPI).\n"
|
|
846 |
+);
|
|
847 |
+static PyObject *
|
|
848 |
+link_get_sdu(pylink_t *link)
|
|
849 |
+{
|
|
850 |
+ dlpi_info_t info;
|
|
851 |
+ int rval;
|
|
852 |
+
|
|
853 |
+ if (link->dlpihdl == NULL) {
|
|
854 |
+ errno = EINVAL;
|
|
855 |
+ dlpi_raise_exception(DL_SYSERR);
|
|
856 |
+ return (NULL);
|
|
857 |
+ }
|
|
858 |
+
|
|
859 |
+ if ((rval = dlpi_info(link->dlpihdl, &info, 0)) !=
|
|
860 |
+ DLPI_SUCCESS) {
|
|
861 |
+ dlpi_raise_exception(rval);
|
|
862 |
+ return (NULL);
|
|
863 |
+ }
|
|
864 |
+
|
|
865 |
+ return (Py_BuildValue("II", info.di_min_sdu, info.di_max_sdu));
|
|
866 |
+}
|
|
867 |
+
|
|
868 |
+PyDoc_STRVAR(get_state_doc,
|
|
869 |
+ "get_state() -> unsigned int\n"
|
|
870 |
+ "\n"
|
|
871 |
+ "Returns current state of the link (either UNBOUND or IDLE).\n"
|
|
872 |
+ "See dlpi_info(3DLPI).\n"
|
|
873 |
+);
|
|
874 |
+static PyObject *
|
|
875 |
+link_get_state(pylink_t *link)
|
|
876 |
+{
|
|
877 |
+ dlpi_info_t info;
|
|
878 |
+ int rval;
|
|
879 |
+
|
|
880 |
+ if (link->dlpihdl == NULL) {
|
|
881 |
+ errno = EINVAL;
|
|
882 |
+ dlpi_raise_exception(DL_SYSERR);
|
|
883 |
+ return (NULL);
|
|
884 |
+ }
|
|
885 |
+
|
|
886 |
+ if ((rval = dlpi_info(link->dlpihdl, &info, 0)) !=
|
|
887 |
+ DLPI_SUCCESS) {
|
|
888 |
+ dlpi_raise_exception(rval);
|
|
889 |
+ return (NULL);
|
|
890 |
+ }
|
|
891 |
+
|
|
892 |
+ return (Py_BuildValue("I", info.di_state));
|
|
893 |
+}
|
|
894 |
+
|
|
895 |
+PyDoc_STRVAR(get_qos_select_doc,
|
|
896 |
+ "get_qos_select() -> (unsigned int, int, int, int)\n"
|
|
897 |
+ "\n"
|
|
898 |
+ "Returns (qos type, trans delay, priority, residul err).\n"
|
|
899 |
+ "Unsupported QOS parameters are set to UNKNOWN.\n"
|
|
900 |
+ "See dlpi_info(3DLPI).\n"
|
|
901 |
+);
|
|
902 |
+static PyObject *
|
|
903 |
+link_get_qos_select(pylink_t *link)
|
|
904 |
+{
|
|
905 |
+ dlpi_info_t info;
|
|
906 |
+ int rval;
|
|
907 |
+
|
|
908 |
+ if (link->dlpihdl == NULL) {
|
|
909 |
+ errno = EINVAL;
|
|
910 |
+ dlpi_raise_exception(DL_SYSERR);
|
|
911 |
+ return (NULL);
|
|
912 |
+ }
|
|
913 |
+
|
|
914 |
+ if ((rval = dlpi_info(link->dlpihdl, &info, 0)) !=
|
|
915 |
+ DLPI_SUCCESS) {
|
|
916 |
+ dlpi_raise_exception(rval);
|
|
917 |
+ return (NULL);
|
|
918 |
+ }
|
|
919 |
+
|
|
920 |
+ return (Py_BuildValue("Iiiii",
|
|
921 |
+ info.di_qos_sel.dl_qos_type,
|
|
922 |
+ info.di_qos_sel.dl_trans_delay,
|
|
923 |
+ info.di_qos_sel.dl_priority,
|
|
924 |
+ info.di_qos_sel.dl_residual_error));
|
|
925 |
+}
|
|
926 |
+
|
|
927 |
+PyDoc_STRVAR(get_qos_range_doc,
|
|
928 |
+ "get_qos_range() -> \n"
|
|
929 |
+ " (unsigned int, (int, int), (int, int), (int, int), int)\n"
|
|
930 |
+ "\n"
|
|
931 |
+ "Returns (qos type, (trans delay target, trans delay accept),\n"
|
|
932 |
+ "(min priority, max priority), (min protection, max protection),\n"
|
|
933 |
+ "residual err).\n"
|
|
934 |
+ "Unsupported QOS range values are set to UNKNOWN.\n"
|
|
935 |
+ "See dlpi_info(3DLPI).\n"
|
|
936 |
+);
|
|
937 |
+static PyObject *
|
|
938 |
+link_get_qos_range(pylink_t *link)
|
|
939 |
+{
|
|
940 |
+ dlpi_info_t info;
|
|
941 |
+ int rval;
|
|
942 |
+
|
|
943 |
+ if (link->dlpihdl == NULL) {
|
|
944 |
+ errno = EINVAL;
|
|
945 |
+ dlpi_raise_exception(DL_SYSERR);
|
|
946 |
+ return (NULL);
|
|
947 |
+ }
|
|
948 |
+
|
|
949 |
+ if ((rval = dlpi_info(link->dlpihdl, &info, 0)) !=
|
|
950 |
+ DLPI_SUCCESS) {
|
|
951 |
+ dlpi_raise_exception(rval);
|
|
952 |
+ return (NULL);
|
|
953 |
+ }
|
|
954 |
+
|
|
955 |
+ return (Py_BuildValue("I(ii)(ii)(ii)i",
|
|
956 |
+ info.di_qos_range.dl_qos_type,
|
|
957 |
+ info.di_qos_range.dl_trans_delay.dl_target_value,
|
|
958 |
+ info.di_qos_range.dl_trans_delay.dl_accept_value,
|
|
959 |
+ info.di_qos_range.dl_priority.dl_min,
|
|
960 |
+ info.di_qos_range.dl_priority.dl_max,
|
|
961 |
+ info.di_qos_range.dl_protection.dl_min,
|
|
962 |
+ info.di_qos_range.dl_protection.dl_max,
|
|
963 |
+ info.di_qos_range.dl_residual_error));
|
|
964 |
+}
|
|
965 |
+
|
|
966 |
+static PyMethodDef pylink_methods[] = {
|
|
967 |
+ {"bind", (PyCFunction)link_bind, METH_VARARGS|METH_KEYWORDS, bind_doc},
|
|
968 |
+ {"unbind", (PyCFunction)link_unbind, METH_NOARGS, unbind_doc},
|
|
969 |
+ {"send", (PyCFunction)link_send, METH_VARARGS|METH_KEYWORDS,
|
|
970 |
+ send_doc},
|
|
971 |
+ {"recv", (PyCFunction)link_recv, METH_VARARGS|METH_KEYWORDS,
|
|
972 |
+ recv_doc},
|
|
973 |
+ {"disabmulti", (PyCFunction)link_disabmulti, METH_VARARGS|METH_KEYWORDS,
|
|
974 |
+ disabmulti_doc},
|
|
975 |
+ {"enabmulti", (PyCFunction)link_enabmulti, METH_VARARGS|METH_KEYWORDS,
|
|
976 |
+ enabmulti_doc},
|
|
977 |
+ {"enabnotify", (PyCFunction)link_enabnotify,
|
|
978 |
+ METH_VARARGS|METH_KEYWORDS, enabnotify_doc},
|
|
979 |
+ {"disabnotify", (PyCFunction)link_disabnotify,
|
|
980 |
+ METH_VARARGS|METH_KEYWORDS, disabnotify_doc},
|
|
981 |
+ {"get_fd", (PyCFunction)link_get_fd, METH_NOARGS, get_fd_doc},
|
|
982 |
+ {"get_sap", (PyCFunction)link_get_sap, METH_NOARGS, get_sap_doc},
|
|
983 |
+ {"get_mactype", (PyCFunction)link_get_mactype, METH_NOARGS,
|
|
984 |
+ get_mactype_doc},
|
|
985 |
+ {"get_linkname", (PyCFunction)link_get_linkname, METH_NOARGS,
|
|
986 |
+ get_linkname_doc},
|
|
987 |
+ {"get_bcastaddr", (PyCFunction)link_get_bcastaddr, METH_NOARGS,
|
|
988 |
+ get_bcastaddr_doc},
|
|
989 |
+ {"get_physaddr", (PyCFunction)link_get_physaddr,
|
|
990 |
+ METH_VARARGS|METH_KEYWORDS, get_physaddr_doc},
|
|
991 |
+ {"set_physaddr", (PyCFunction)link_set_physaddr,
|
|
992 |
+ METH_VARARGS|METH_KEYWORDS, set_physaddr_doc},
|
|
993 |
+ {"promiscon", (PyCFunction)link_promiscon, METH_VARARGS|METH_KEYWORDS,
|
|
994 |
+ promiscon_doc},
|
|
995 |
+ {"promiscoff", (PyCFunction)link_promiscoff, METH_VARARGS|METH_KEYWORDS,
|
|
996 |
+ promiscoff_doc},
|
|
997 |
+ {"get_timeout", (PyCFunction)link_get_timeout, METH_NOARGS,
|
|
998 |
+ get_timeout_doc},
|
|
999 |
+ {"set_timeout", (PyCFunction)link_set_timeout,
|
|
1000 |
+ METH_VARARGS|METH_KEYWORDS, set_timeout_doc},
|
|
1001 |
+ {"get_sdu", (PyCFunction)link_get_sdu, METH_NOARGS, get_sdu_doc},
|
|
1002 |
+ {"get_state", (PyCFunction)link_get_state, METH_NOARGS,
|
|
1003 |
+ get_state_doc},
|
|
1004 |
+ {"get_qos_select", (PyCFunction)link_get_qos_select, METH_NOARGS,
|
|
1005 |
+ get_qos_select_doc},
|
|
1006 |
+ {"get_qos_range", (PyCFunction)link_get_qos_range, METH_NOARGS,
|
|
1007 |
+ get_qos_range_doc},
|
|
1008 |
+ {NULL}
|
|
1009 |
+};
|
|
1010 |
+
|
|
1011 |
+static PyTypeObject pylink_type = {
|
|
1012 |
+ PyObject_HEAD_INIT(0) /* Must fill in type value later */
|
|
1013 |
+ 0, /* ob_size */
|
|
1014 |
+ "dlpi.link", /* tp_name */
|
|
1015 |
+ sizeof(pylink_t), /* tp_basicsize */
|
|
1016 |
+ 0, /* tp_itemsize */
|
|
1017 |
+ (destructor)link_dealloc, /* tp_dealloc */
|
|
1018 |
+ 0, /* tp_print */
|
|
1019 |
+ 0, /* tp_getattr */
|
|
1020 |
+ 0, /* tp_setattr */
|
|
1021 |
+ 0, /* tp_compare */
|
|
1022 |
+ 0, /* tp_repr */
|
|
1023 |
+ 0, /* tp_as_number */
|
|
1024 |
+ 0, /* tp_as_sequence */
|
|
1025 |
+ 0, /* tp_as_mapping */
|
|
1026 |
+ 0, /* tp_hash */
|
|
1027 |
+ 0, /* tp_call */
|
|
1028 |
+ 0, /* tp_str */
|
|
1029 |
+ 0, /* tp_getattro */
|
|
1030 |
+ 0, /* tp_setattro */
|
|
1031 |
+ 0, /* tp_as_buffer */
|
|
1032 |
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
|
|
1033 |
+ link_doc, /* tp_doc */
|
|
1034 |
+ 0, /* tp_traverse */
|
|
1035 |
+ 0, /* tp_clear */
|
|
1036 |
+ 0, /* tp_richcompare */
|
|
1037 |
+ 0, /* tp_weaklistoffset */
|
|
1038 |
+ 0, /* tp_iter */
|
|
1039 |
+ 0, /* tp_iternext */
|
|
1040 |
+ pylink_methods, /* tp_methods */
|
|
1041 |
+ 0, /* tp_members */
|
|
1042 |
+ 0, /* tp_getset */
|
|
1043 |
+ 0, /* tp_base */
|
|
1044 |
+ 0, /* tp_dict */
|
|
1045 |
+ 0, /* tp_descr_get */
|
|
1046 |
+ 0, /* tp_descr_set */
|
|
1047 |
+ 0, /* tp_dictoffset */
|
|
1048 |
+ (initproc)link_init, /* tp_init */
|
|
1049 |
+ 0, /* tp_alloc */
|
|
1050 |
+ PyType_GenericNew, /* tp_new */
|
|
1051 |
+ 0, /* tp_free */
|
|
1052 |
+};
|
|
1053 |
+
|
|
1054 |
+PyDoc_STRVAR(arptype_doc,
|
|
1055 |
+ "arptype(arptype) -> unsigned int\n"
|
|
1056 |
+ "\n"
|
|
1057 |
+ "Converts a DLPI MAC type to an ARP hardware type defined\n"
|
|
1058 |
+ " in <netinet/arp.h>\n"
|
|
1059 |
+ "See dlpi_arptype(3DLPI)\n"
|
|
1060 |
+);
|
|
1061 |
+static PyObject *
|
|
1062 |
+arptype(PyObject *dlpi, PyObject *args, PyObject *kwds)
|
|
1063 |
+{
|
|
1064 |
+ static char *keywords[] = {"arptype", NULL};
|
|
1065 |
+ uint_t dlpityp, arptyp;
|
|
1066 |
+
|
|
1067 |
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "I", keywords, &dlpityp))
|
|
1068 |
+ return (NULL);
|
|
1069 |
+
|
|
1070 |
+ if ((arptyp = dlpi_arptype(dlpityp)) == 0) {
|
|
1071 |
+ errno = EINVAL;
|
|
1072 |
+ dlpi_raise_exception(DL_SYSERR);
|
|
1073 |
+ return (NULL);
|
|
1074 |
+ }
|
|
1075 |
+
|
|
1076 |
+ return (Py_BuildValue("I", arptyp));
|
|
1077 |
+}
|
|
1078 |
+
|
|
1079 |
+PyDoc_STRVAR(iftype_doc,
|
|
1080 |
+ "iftype(iftype) -> unsigned int\n"
|
|
1081 |
+ "\n"
|
|
1082 |
+ "Converts a DLPI MAC type to a BSD socket interface type\n"
|
|
1083 |
+ "defined in <net/if_types.h>\n"
|
|
1084 |
+ "See dlpi_iftype(3DLPI)\n"
|
|
1085 |
+);
|
|
1086 |
+static PyObject *
|
|
1087 |
+iftype(PyObject *dlpi, PyObject *args, PyObject *kwds)
|
|
1088 |
+{
|
|
1089 |
+ static char *keywords[] = {"iftype", NULL};
|
|
1090 |
+ uint_t dlpityp, iftyp;
|
|
1091 |
+
|
|
1092 |
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "I", keywords, &dlpityp))
|
|
1093 |
+ return (NULL);
|
|
1094 |
+
|
|
1095 |
+ if ((iftyp = dlpi_iftype(dlpityp)) == 0) {
|
|
1096 |
+ errno = EINVAL;
|
|
1097 |
+ dlpi_raise_exception(DL_SYSERR);
|
|
1098 |
+ return (NULL);
|
|
1099 |
+ }
|
|
1100 |
+
|
|
1101 |
+ return (Py_BuildValue("I", iftyp));
|
|
1102 |
+}
|
|
1103 |
+
|
|
1104 |
+PyDoc_STRVAR(mactype_doc,
|
|
1105 |
+ "mactype(mactype) -> string\n"
|
|
1106 |
+ "\n"
|
|
1107 |
+ "Returns a string that describes the specified mactype.\n"
|
|
1108 |
+ "Valid mac types are defined in <sys/dlpi.h>.\n"
|
|
1109 |
+ "See dlpi_mactype(3DLPI)\n"
|
|
1110 |
+);
|
|
1111 |
+static PyObject *
|
|
1112 |
+mactype(PyObject *dlpi, PyObject *args, PyObject *kwds)
|
|
1113 |
+{
|
|
1114 |
+ static char *keywords[] = {"mactype", NULL};
|
|
1115 |
+ uint_t mactyp;
|
|
1116 |
+
|
|
1117 |
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "I", keywords, &mactyp))
|
|
1118 |
+ return (NULL);
|
|
1119 |
+
|
|
1120 |
+ return (Py_BuildValue("s", dlpi_mactype(mactyp)));
|
|
1121 |
+}
|
|
1122 |
+
|
|
1123 |
+static boolean_t
|
|
1124 |
+link_walker(const char *name, void *arg)
|
|
1125 |
+{
|
|
1126 |
+ PyObject *linkname;
|
|
1127 |
+ PyObject *list = (PyObject *)arg;
|
|
1128 |
+
|
|
1129 |
+ if ((list == NULL) || !PyList_Check(list))
|
|
1130 |
+ return (B_FALSE);
|
|
1131 |
+
|
|
1132 |
+ linkname = Py_BuildValue("s", name);
|
|
1133 |
+ if (PyList_Append(list, linkname) == -1)
|
< |