89 lines
2.4 KiB
C
89 lines
2.4 KiB
C
/******************************************************************************
|
|
* Copyright (c) Huawei Technologies Co., Ltd. 2017-2019. All rights reserved.
|
|
* isulad-tools is licensed under the Mulan PSL v1.
|
|
* You can use this software according to the terms and conditions of the Mulan PSL v1.
|
|
* You may obtain a copy of Mulan PSL v1 at:
|
|
* http://license.coscl.org.cn/MulanPSL
|
|
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
|
* PURPOSE.
|
|
* See the Mulan PSL v1 for more details.
|
|
* Author: zhangwentao
|
|
* Create: 2017-07-19
|
|
* Description: config net device tx/sg/tso on
|
|
******************************************************************************/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <securec.h>
|
|
#include <sys/types.h>
|
|
#include <unistd.h>
|
|
#include <endian.h>
|
|
#include <sys/ioctl.h>
|
|
#include <sys/socket.h>
|
|
#include <linux/sockios.h>
|
|
#include <netinet/in.h>
|
|
#include <net/if.h>
|
|
#include <linux/netlink.h>
|
|
#include <linux/ethtool.h>
|
|
|
|
int setNetDeviceTSO(int fd, char* name, int on)
|
|
{
|
|
struct ifreq ifr = {0};
|
|
struct ethtool_value eval = {0};
|
|
int ret;
|
|
eval.data = on;
|
|
eval.cmd = ETHTOOL_STSO;
|
|
|
|
ret = strncpy_s(ifr.ifr_name, sizeof(ifr.ifr_name), name, sizeof(ifr.ifr_name) - 1);
|
|
if (ret != EOK) {
|
|
return -1;
|
|
}
|
|
ifr.ifr_data = (void*)&eval;
|
|
ret = ioctl(fd, SIOCETHTOOL, &ifr);
|
|
if (ret < 0) {
|
|
return -1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int setNetDeviceSG(int fd, char* name, int on)
|
|
{
|
|
struct ifreq ifr = {0};
|
|
struct ethtool_value eval = {0};
|
|
int ret;
|
|
eval.data = on;
|
|
eval.cmd = ETHTOOL_SSG;
|
|
|
|
ret = strncpy_s(ifr.ifr_name, sizeof(ifr.ifr_name), name, sizeof(ifr.ifr_name) - 1);
|
|
if (ret != EOK) {
|
|
return -1;
|
|
}
|
|
ifr.ifr_data = (void*)&eval;
|
|
ret = ioctl(fd, SIOCETHTOOL, &ifr);
|
|
if (ret < 0) {
|
|
return -1;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int setNetDeviceTX(int fd, char* name, int on)
|
|
{
|
|
struct ifreq ifr = {0};
|
|
struct ethtool_value eval = {0};
|
|
int ret;
|
|
eval.data = on;
|
|
eval.cmd = ETHTOOL_STXCSUM;
|
|
|
|
ret = strncpy_s(ifr.ifr_name, sizeof(ifr.ifr_name), name, sizeof(ifr.ifr_name) - 1);
|
|
if (ret != EOK) {
|
|
return -1;
|
|
}
|
|
ifr.ifr_data = (void*)&eval;
|
|
ret = ioctl(fd, SIOCETHTOOL, &ifr);
|
|
if (ret < 0) {
|
|
return -1;
|
|
}
|
|
return 0;
|
|
}
|