ethtool-util.c revision 0a1beeb64207eaa88ab9236787b1cbc2f704ae14
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright (C) 2013 Tom Gundersen <teg@jklm.no>
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include "ethtool-util.h"
#include "strxcpyx.h"
#include "util.h"
#include "log.h"
#include "conf-parser.h"
static const char* const duplex_table[_DUP_MAX] = {
[DUP_FULL] = "full",
[DUP_HALF] = "half"
};
[WOL_PHY] = "phy",
[WOL_MAGIC] = "magic",
[WOL_OFF] = "off"
};
int ethtool_connect(int *ret) {
int fd;
if (fd < 0) {
return -errno;
}
return 0;
}
struct ethtool_drvinfo ecmd = {
};
};
char *d;
int r;
if (*fd < 0) {
r = ethtool_connect(fd);
if (r < 0) {
log_warning_errno(-r, "link_config: could not connect to ethtool: %m");
return r;
}
}
if (r < 0)
return -errno;
if (!d)
return -ENOMEM;
*ret = d;
return 0;
}
{
struct ethtool_cmd ecmd = {
.cmd = ETHTOOL_GSET
};
};
bool need_update = false;
int r;
return 0;
if (*fd < 0) {
r = ethtool_connect(fd);
if (r < 0) {
log_warning_errno(-r, "link_config: could not connect to ethtool: %m");
return r;
}
}
if (r < 0)
return -errno;
need_update = true;
}
switch (duplex) {
case DUP_HALF:
need_update = true;
}
break;
case DUP_FULL:
need_update = true;
}
break;
default:
break;
}
if (need_update) {
if (r < 0)
return -errno;
}
return 0;
}
struct ethtool_wolinfo ecmd = {
.cmd = ETHTOOL_GWOL
};
};
bool need_update = false;
int r;
if (wol == _WOL_INVALID)
return 0;
if (*fd < 0) {
r = ethtool_connect(fd);
if (r < 0) {
log_warning_errno(-r, "link_config: could not connect to ethtool: %m");
return r;
}
}
if (r < 0)
return -errno;
switch (wol) {
case WOL_PHY:
need_update = true;
}
break;
case WOL_MAGIC:
need_update = true;
}
break;
case WOL_OFF:
need_update = true;
}
break;
default:
break;
}
if (need_update) {
if (r < 0)
return -errno;
}
return 0;
}