Skip to content

Commit cda854a

Browse files
authored
[vs] Support set interface ADMIN status (sonic-net#558)
* [vs] Support set interface ADMIN status * [vs] Fix spelling
1 parent 2961bd3 commit cda854a

File tree

2 files changed

+65
-8
lines changed

2 files changed

+65
-8
lines changed

vslib/src/sai_vs_hostintf.cpp

+54-8
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,9 @@ void send_port_up_notification(
901901

902902
int ifup(
903903
_In_ const char *dev,
904-
_In_ sai_object_id_t port_id)
904+
_In_ sai_object_id_t port_id,
905+
_In_ bool up,
906+
_In_ bool explicitNotification)
905907
{
906908
SWSS_LOG_ENTER();
907909

@@ -931,7 +933,7 @@ int ifup(
931933
return err;
932934
}
933935

934-
if (ifr.ifr_flags & IFF_UP)
936+
if (up && explicitNotification && (ifr.ifr_flags & IFF_UP))
935937
{
936938
close(s);
937939

@@ -946,7 +948,14 @@ int ifup(
946948
return 0;
947949
}
948950

949-
ifr.ifr_flags |= IFF_UP;
951+
if (up)
952+
{
953+
ifr.ifr_flags |= IFF_UP;
954+
}
955+
else
956+
{
957+
ifr.ifr_flags &= ~IFF_UP;
958+
}
950959

951960
err = ioctl(s, SIOCSIFFLAGS, &ifr);
952961

@@ -1094,8 +1103,11 @@ void hostif_info_t::veth2tap_fun()
10941103

10951104
if (size < 0)
10961105
{
1097-
SWSS_LOG_ERROR("failed to read from socket fd %d, errno(%d): %s",
1098-
packet_socket, errno, strerror(errno));
1106+
if (errno != ENETDOWN)
1107+
{
1108+
SWSS_LOG_ERROR("failed to read from socket fd %d, errno(%d): %s",
1109+
packet_socket, errno, strerror(errno));
1110+
}
10991111

11001112
continue;
11011113
}
@@ -1215,8 +1227,11 @@ void hostif_info_t::tap2veth_fun()
12151227

12161228
if (write(packet_socket, buffer, (int)size) < 0)
12171229
{
1218-
SWSS_LOG_ERROR("failed to write to socket fd %d, errno(%d): %s",
1219-
packet_socket, errno, strerror(errno));
1230+
if (errno != ENETDOWN)
1231+
{
1232+
SWSS_LOG_ERROR("failed to write to socket fd %d, errno(%d): %s",
1233+
packet_socket, errno, strerror(errno));
1234+
}
12201235

12211236
continue;
12221237
}
@@ -1319,7 +1334,7 @@ bool hostif_create_tap_veth_forwarding(
13191334

13201335
SWSS_LOG_INFO("interface index = %d %s\n", sock_address.sll_ifindex, vethname.c_str());
13211336

1322-
if (ifup(vethname.c_str(), port_id))
1337+
if (ifup(vethname.c_str(), port_id, true, true))
13231338
{
13241339
SWSS_LOG_ERROR("ifup failed on %s", vethname.c_str());
13251340

@@ -1681,6 +1696,37 @@ sai_status_t vs_create_hostif(
16811696
&vs_create_hostif_int);
16821697
}
16831698

1699+
sai_status_t vs_set_admin_state(
1700+
_In_ sai_object_id_t portId,
1701+
_In_ bool up)
1702+
{
1703+
SWSS_LOG_ENTER();
1704+
1705+
// find corresponding host if interface and bring it down !
1706+
for (auto& kvp: hostif_info_map)
1707+
{
1708+
auto tapname = kvp.first;
1709+
1710+
if (kvp.second->portid == portId)
1711+
{
1712+
std::string vethname = vs_get_veth_name(tapname, portId);
1713+
1714+
if (ifup(vethname.c_str(), portId, up, false))
1715+
{
1716+
SWSS_LOG_ERROR("if admin %s failed on %s failed: %s", (up ? "UP" : "DOWN"), vethname.c_str(), strerror(errno));
1717+
1718+
return SAI_STATUS_FAILURE;
1719+
}
1720+
1721+
SWSS_LOG_NOTICE("if admin %s success on %s", (up ? "UP" : "DOWN"), vethname.c_str());
1722+
1723+
break;
1724+
}
1725+
}
1726+
1727+
return SAI_STATUS_SUCCESS;
1728+
}
1729+
16841730
// TODO set must also be supported when we change operational status up/down
16851731
// and probably also generate notification then
16861732

vslib/src/sai_vs_port.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -517,13 +517,24 @@ sai_status_t vs_remove_port(
517517
return SAI_STATUS_SUCCESS;
518518
}
519519

520+
sai_status_t vs_set_admin_state(
521+
_In_ sai_object_id_t port_id,
522+
_In_ bool up);
523+
520524
sai_status_t vs_set_port_attribute(
521525
_In_ sai_object_id_t port_id,
522526
_In_ const sai_attribute_t *attr)
523527
{
524528
MUTEX();
525529
SWSS_LOG_ENTER();
526530

531+
if (attr && attr->id == SAI_PORT_ATTR_ADMIN_STATE)
532+
{
533+
bool up = attr->value.booldata;
534+
535+
vs_set_admin_state(port_id, up);
536+
}
537+
527538
std::string cmd;
528539

529540
// Special handling for the sampling attribute modification

0 commit comments

Comments
 (0)