@@ -416,6 +416,37 @@ bool IntfsOrch::setIntfProxyArp(const string &alias, const string &proxy_arp)
416
416
return true ;
417
417
}
418
418
419
+ bool IntfsOrch::setIntfLoopbackAction (const Port &port, string actionStr)
420
+ {
421
+ sai_attribute_t attr;
422
+ sai_packet_action_t action;
423
+
424
+ if (!getSaiLoopbackAction (actionStr, action))
425
+ {
426
+ return false ;
427
+ }
428
+
429
+ attr.id = SAI_ROUTER_INTERFACE_ATTR_LOOPBACK_PACKET_ACTION;
430
+ attr.value .s32 = action;
431
+
432
+ sai_status_t status = sai_router_intfs_api->set_router_interface_attribute (port.m_rif_id , &attr);
433
+ if (status != SAI_STATUS_SUCCESS)
434
+ {
435
+ SWSS_LOG_ERROR (" Loopback action [%s] set failed, interface [%s], rc [%d]" ,
436
+ actionStr.c_str (), port.m_alias .c_str (), status);
437
+
438
+ task_process_status handle_status = handleSaiSetStatus (SAI_API_ROUTER_INTERFACE, status);
439
+ if (handle_status != task_success)
440
+ {
441
+ return parseHandleSaiStatusFailure (handle_status);
442
+ }
443
+ }
444
+
445
+ SWSS_LOG_NOTICE (" Loopback action [%s] set success, interface [%s]" ,
446
+ actionStr.c_str (), port.m_alias .c_str ());
447
+ return true ;
448
+ }
449
+
419
450
set<IpPrefix> IntfsOrch:: getSubnetRoutes()
420
451
{
421
452
SWSS_LOG_ENTER ();
@@ -433,7 +464,9 @@ set<IpPrefix> IntfsOrch:: getSubnetRoutes()
433
464
return subnet_routes;
434
465
}
435
466
436
- bool IntfsOrch::setIntf (const string& alias, sai_object_id_t vrf_id, const IpPrefix *ip_prefix, const bool adminUp, const uint32_t mtu)
467
+ bool IntfsOrch::setIntf (const string& alias, sai_object_id_t vrf_id, const IpPrefix *ip_prefix,
468
+ const bool adminUp, const uint32_t mtu, string loopbackAction)
469
+
437
470
{
438
471
SWSS_LOG_ENTER ();
439
472
@@ -443,7 +476,7 @@ bool IntfsOrch::setIntf(const string& alias, sai_object_id_t vrf_id, const IpPre
443
476
auto it_intfs = m_syncdIntfses.find (alias);
444
477
if (it_intfs == m_syncdIntfses.end ())
445
478
{
446
- if (!ip_prefix && addRouterIntfs (vrf_id, port))
479
+ if (!ip_prefix && addRouterIntfs (vrf_id, port, loopbackAction ))
447
480
{
448
481
gPortsOrch ->increasePortRefCount (alias);
449
482
IntfsEntry intfs_entry;
@@ -665,6 +698,7 @@ void IntfsOrch::doTask(Consumer &consumer)
665
698
string inband_type = " " ;
666
699
bool mpls = false ;
667
700
string vlan = " " ;
701
+ string loopbackAction = " " ;
668
702
669
703
for (auto idx : data)
670
704
{
@@ -757,6 +791,10 @@ void IntfsOrch::doTask(Consumer &consumer)
757
791
{
758
792
vlan = value;
759
793
}
794
+ else if (field == " loopback_action" )
795
+ {
796
+ loopbackAction = value;
797
+ }
760
798
}
761
799
762
800
if (alias == " eth0" || alias == " docker0" )
@@ -874,7 +912,8 @@ void IntfsOrch::doTask(Consumer &consumer)
874
912
{
875
913
adminUp = port.m_admin_state_up ;
876
914
}
877
- if (!setIntf (alias, vrf_id, ip_prefix_in_key ? &ip_prefix : nullptr , adminUp, mtu))
915
+
916
+ if (!setIntf (alias, vrf_id, ip_prefix_in_key ? &ip_prefix : nullptr , adminUp, mtu, loopbackAction))
878
917
{
879
918
it++;
880
919
continue ;
@@ -906,6 +945,12 @@ void IntfsOrch::doTask(Consumer &consumer)
906
945
setRouterIntfsMpls (port);
907
946
gPortsOrch ->setPort (alias, port);
908
947
}
948
+
949
+ /* Set loopback action */
950
+ if (!loopbackAction.empty ())
951
+ {
952
+ setIntfLoopbackAction (port, loopbackAction);
953
+ }
909
954
}
910
955
}
911
956
@@ -1047,7 +1092,28 @@ void IntfsOrch::doTask(Consumer &consumer)
1047
1092
}
1048
1093
}
1049
1094
1050
- bool IntfsOrch::addRouterIntfs (sai_object_id_t vrf_id, Port &port)
1095
+ bool IntfsOrch::getSaiLoopbackAction (const string &actionStr, sai_packet_action_t &action)
1096
+ {
1097
+ const unordered_map<string, sai_packet_action_t > loopbackActionMap =
1098
+ {
1099
+ {" drop" , SAI_PACKET_ACTION_DROP},
1100
+ {" forward" , SAI_PACKET_ACTION_FORWARD},
1101
+ };
1102
+
1103
+ auto it = loopbackActionMap.find (actionStr);
1104
+ if (it != loopbackActionMap.end ())
1105
+ {
1106
+ action = loopbackActionMap.at (actionStr);
1107
+ return true ;
1108
+ }
1109
+ else
1110
+ {
1111
+ SWSS_LOG_WARN (" Unsupported loopback action [%s]" , actionStr.c_str ());
1112
+ return false ;
1113
+ }
1114
+ }
1115
+
1116
+ bool IntfsOrch::addRouterIntfs (sai_object_id_t vrf_id, Port &port, string loopbackActionStr)
1051
1117
{
1052
1118
SWSS_LOG_ENTER ();
1053
1119
@@ -1067,6 +1133,17 @@ bool IntfsOrch::addRouterIntfs(sai_object_id_t vrf_id, Port &port)
1067
1133
attr.value .oid = vrf_id;
1068
1134
attrs.push_back (attr);
1069
1135
1136
+ if (!loopbackActionStr.empty ())
1137
+ {
1138
+ sai_packet_action_t loopbackAction;
1139
+ if (getSaiLoopbackAction (loopbackActionStr, loopbackAction))
1140
+ {
1141
+ attr.id = SAI_ROUTER_INTERFACE_ATTR_LOOPBACK_PACKET_ACTION;
1142
+ attr.value .s32 = loopbackAction;
1143
+ attrs.push_back (attr);
1144
+ }
1145
+ }
1146
+
1070
1147
attr.id = SAI_ROUTER_INTERFACE_ATTR_SRC_MAC_ADDRESS;
1071
1148
if (port.m_mac )
1072
1149
{
0 commit comments