Skip to content

Commit 90517c2

Browse files
committed
ethtool: implement set_tso
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 92cd328 commit 90517c2

File tree

1 file changed

+48
-12
lines changed

1 file changed

+48
-12
lines changed

python-ethtool/ethtool.c

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -405,25 +405,20 @@ static PyObject *get_businfo(PyObject *self __unused, PyObject *args)
405405
return PyString_FromString(((struct ethtool_drvinfo *)buf)->bus_info);
406406
}
407407

408-
static int get_dev_value(int cmd, PyObject *args, void *value, size_t len)
408+
static int send_command(int cmd, char *devname, struct ethtool_value *eval)
409409
{
410-
struct ethtool_value eval;
411-
struct ifreq ifr;
410+
/* Setup our control structures. */
412411
int fd, err;
413-
char *devname;
414-
415-
if (!PyArg_ParseTuple(args, "s", &devname))
416-
return -1;
412+
struct ifreq ifr;
417413

418-
/* Setup our control structures. */
419414
memset(&ifr, 0, sizeof(ifr));
420415
strncpy(&ifr.ifr_name[0], devname, IFNAMSIZ);
421416
ifr.ifr_name[IFNAMSIZ - 1] = 0;
422-
ifr.ifr_data = (caddr_t)&eval;
423-
eval.cmd = cmd;
417+
ifr.ifr_data = (caddr_t)eval;
418+
eval->cmd = cmd;
424419

425420
/* Open control socket. */
426-
fd = socket(AF_INET, SOCK_DGRAM, 0);
421+
fd = socket(AF_INET, SOCK_DGRAM, 0), err;
427422
if (fd < 0) {
428423
PyErr_SetString(PyExc_OSError, strerror(errno));
429424
return -1;
@@ -438,7 +433,20 @@ static int get_dev_value(int cmd, PyObject *args, void *value, size_t len)
438433
}
439434

440435
close(fd);
441-
memcpy(value, eval.data, len);
436+
return err;
437+
}
438+
439+
static int get_dev_value(int cmd, PyObject *args, void *value, size_t len)
440+
{
441+
char *devname;
442+
int err = -1;
443+
444+
if (PyArg_ParseTuple(args, "s", &devname)) {
445+
struct ethtool_value eval;
446+
/* Setup our control structures. */
447+
err = send_command(cmd, devname, &eval);
448+
memcpy(value, &eval.data, len);
449+
}
442450

443451
return err;
444452
}
@@ -448,6 +456,17 @@ static int get_dev_int_value(int cmd, PyObject *args, int *value)
448456
return get_dev_value(cmd, args, value, sizeof(*value));
449457
}
450458

459+
static int dev_set_int_value(int cmd, PyObject *args)
460+
{
461+
struct ethtool_value eval;
462+
char *devname;
463+
464+
if (!PyArg_ParseTuple(args, "si", &devname, &eval.data))
465+
return -1;
466+
467+
return send_command(cmd, devname, &eval);
468+
}
469+
451470
static PyObject *get_tso(PyObject *self __unused, PyObject *args)
452471
{
453472
int value;
@@ -458,6 +477,18 @@ static PyObject *get_tso(PyObject *self __unused, PyObject *args)
458477
return Py_BuildValue("b", value);
459478
}
460479

480+
static PyObject *set_tso(PyObject *self __unused, PyObject *args)
481+
{
482+
int pid, policy, priority;
483+
struct ethtool_value param;
484+
485+
if (dev_set_int_value(ETHTOOL_STSO, args) < 0)
486+
return NULL;
487+
488+
Py_INCREF(Py_None);
489+
return Py_None;
490+
}
491+
461492
static PyObject *get_ufo(PyObject *self __unused, PyObject *args)
462493
{
463494
int value;
@@ -534,6 +565,11 @@ static struct PyMethodDef PyEthModuleMethods[] = {
534565
.ml_meth = (PyCFunction)get_tso,
535566
.ml_flags = METH_VARARGS,
536567
},
568+
{
569+
.ml_name = "set_tso",
570+
.ml_meth = (PyCFunction)set_tso,
571+
.ml_flags = METH_VARARGS,
572+
},
537573
{
538574
.ml_name = "get_ufo",
539575
.ml_meth = (PyCFunction)get_ufo,

0 commit comments

Comments
 (0)