Skip to content

Commit aaf2fb1

Browse files
committed
netdev-linux: Reorganize slightly.
1 parent 52e2fbf commit aaf2fb1

1 file changed

Lines changed: 49 additions & 48 deletions

File tree

lib/netdev-linux.c

Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3930,6 +3930,55 @@ tc_calc_buffer(unsigned int Bps, int mtu, uint64_t burst_bytes)
39303930
return tc_bytes_to_ticks(Bps, MAX(burst_bytes, min_burst));
39313931
}
39323932

3933+
/* Linux-only functions declared in netdev-linux.h */
3934+
3935+
/* Modifies the 'flag' bit in ethtool's flags field for 'netdev'. If
3936+
* 'enable' is true, the bit is set. Otherwise, it is cleared. */
3937+
int
3938+
netdev_linux_ethtool_set_flag(struct netdev *netdev, uint32_t flag,
3939+
const char *flag_name, bool enable)
3940+
{
3941+
const char *netdev_name = netdev_get_name(netdev);
3942+
struct ethtool_value evalue;
3943+
uint32_t new_flags;
3944+
int error;
3945+
3946+
memset(&evalue, 0, sizeof evalue);
3947+
error = netdev_linux_do_ethtool(netdev_name,
3948+
(struct ethtool_cmd *)&evalue,
3949+
ETHTOOL_GFLAGS, "ETHTOOL_GFLAGS");
3950+
if (error) {
3951+
return error;
3952+
}
3953+
3954+
evalue.data = new_flags = (evalue.data & ~flag) | (enable ? flag : 0);
3955+
error = netdev_linux_do_ethtool(netdev_name,
3956+
(struct ethtool_cmd *)&evalue,
3957+
ETHTOOL_SFLAGS, "ETHTOOL_SFLAGS");
3958+
if (error) {
3959+
return error;
3960+
}
3961+
3962+
memset(&evalue, 0, sizeof evalue);
3963+
error = netdev_linux_do_ethtool(netdev_name,
3964+
(struct ethtool_cmd *)&evalue,
3965+
ETHTOOL_GFLAGS, "ETHTOOL_GFLAGS");
3966+
if (error) {
3967+
return error;
3968+
}
3969+
3970+
if (new_flags != evalue.data) {
3971+
VLOG_WARN_RL(&rl, "attempt to %s ethtool %s flag on network "
3972+
"device %s failed", enable ? "enable" : "disable",
3973+
flag_name, netdev_name);
3974+
return EOPNOTSUPP;
3975+
}
3976+
3977+
return 0;
3978+
}
3979+
3980+
/* Utility functions. */
3981+
39333982
/* Copies 'src' into 'dst', performing format conversion in the process. */
39343983
static void
39353984
netdev_stats_from_rtnl_link_stats(struct netdev_stats *dst,
@@ -3958,9 +4007,6 @@ netdev_stats_from_rtnl_link_stats(struct netdev_stats *dst,
39584007
dst->tx_window_errors = src->tx_window_errors;
39594008
}
39604009

3961-
3962-
/* Utility functions. */
3963-
39644010
static int
39654011
get_stats_via_netlink(int ifindex, struct netdev_stats *stats)
39664012
{
@@ -4247,51 +4293,6 @@ netdev_linux_do_ethtool(const char *name, struct ethtool_cmd *ecmd,
42474293
}
42484294
}
42494295

4250-
/* Modifies the 'flag' bit in ethtool's flags field for 'netdev'. If
4251-
* 'enable' is true, the bit is set. Otherwise, it is cleared. */
4252-
int
4253-
netdev_linux_ethtool_set_flag(struct netdev *netdev, uint32_t flag,
4254-
const char *flag_name, bool enable)
4255-
{
4256-
const char *netdev_name = netdev_get_name(netdev);
4257-
struct ethtool_value evalue;
4258-
uint32_t new_flags;
4259-
int error;
4260-
4261-
memset(&evalue, 0, sizeof evalue);
4262-
error = netdev_linux_do_ethtool(netdev_name,
4263-
(struct ethtool_cmd *)&evalue,
4264-
ETHTOOL_GFLAGS, "ETHTOOL_GFLAGS");
4265-
if (error) {
4266-
return error;
4267-
}
4268-
4269-
evalue.data = new_flags = (evalue.data & ~flag) | (enable ? flag : 0);
4270-
error = netdev_linux_do_ethtool(netdev_name,
4271-
(struct ethtool_cmd *)&evalue,
4272-
ETHTOOL_SFLAGS, "ETHTOOL_SFLAGS");
4273-
if (error) {
4274-
return error;
4275-
}
4276-
4277-
memset(&evalue, 0, sizeof evalue);
4278-
error = netdev_linux_do_ethtool(netdev_name,
4279-
(struct ethtool_cmd *)&evalue,
4280-
ETHTOOL_GFLAGS, "ETHTOOL_GFLAGS");
4281-
if (error) {
4282-
return error;
4283-
}
4284-
4285-
if (new_flags != evalue.data) {
4286-
VLOG_WARN_RL(&rl, "attempt to %s ethtool %s flag on network "
4287-
"device %s failed", enable ? "enable" : "disable",
4288-
flag_name, netdev_name);
4289-
return EOPNOTSUPP;
4290-
}
4291-
4292-
return 0;
4293-
}
4294-
42954296
static int
42964297
netdev_linux_do_ioctl(const char *name, struct ifreq *ifr, int cmd,
42974298
const char *cmd_name)

0 commit comments

Comments
 (0)