-
Notifications
You must be signed in to change notification settings - Fork 686
RouteSync::onMsg supports ipv6 route #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,34 +25,27 @@ void RouteSync::onMsg(int nlmsg_type, struct nl_object *obj) | |
| { | ||
| struct rtnl_route *route_obj = (struct rtnl_route *)obj; | ||
| struct nl_addr *dip; | ||
| char ifname[MAX_ADDR_SIZE + 1] = {0}; | ||
| uint32_t ipv4; | ||
| int prefix; | ||
| char destipprefix[MAX_ADDR_SIZE + 1] = {0}; | ||
|
|
||
| dip = rtnl_route_get_dst(route_obj); | ||
| /* Supports IPv4 address only for now */ | ||
| if (rtnl_route_get_family(route_obj) != AF_INET) | ||
| nl_addr2str(dip, destipprefix, MAX_ADDR_SIZE); | ||
| SWSS_LOG_DEBUG("Receive new route message dest ip prefix: %s\n", destipprefix); | ||
| /* Supports IPv4 or IPv6 address, otherwise return immediately */ | ||
| auto family = rtnl_route_get_family(route_obj); | ||
| if (family != AF_INET && family != AF_INET6) | ||
| { | ||
| nl_addr2str(dip, ifname, MAX_ADDR_SIZE); | ||
| SWSS_LOG_INFO("%s: Unknown route family support: %s (object: %s)\n", | ||
| __FUNCTION__, ifname, nl_object_get_type(obj)); | ||
| SWSS_LOG_INFO("Unknown route family support: %s (object: %s)\n", destipprefix, nl_object_get_type(obj)); | ||
| return; | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change this to if (family != AF_NET and family != AF_INET) return. it's more clear then switch.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolved. |
||
|
|
||
| prefix = nl_addr_get_prefixlen(dip); | ||
| ipv4 = *(uint32_t*)nl_addr_get_binary_addr(dip); | ||
| IpPrefix destip(ipv4, prefix); | ||
|
|
||
| if (nlmsg_type == RTM_DELROUTE) | ||
| { | ||
| m_routeTable.del(destip.to_string()); | ||
| m_routeTable.del(destipprefix); | ||
| return; | ||
| } | ||
| else if (nlmsg_type != RTM_NEWROUTE) | ||
| { | ||
| nl_addr2str(dip, ifname, MAX_ADDR_SIZE); | ||
| SWSS_LOG_INFO("%s: Unknown message-type: %d for %s\n", | ||
| __FUNCTION__, nlmsg_type, ifname); | ||
| SWSS_LOG_INFO("Unknown message-type: %d for %s\n", nlmsg_type, destipprefix); | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -63,7 +56,7 @@ void RouteSync::onMsg(int nlmsg_type, struct nl_object *obj) | |
| std::vector<FieldValueTuple> fvVector; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove the std:: and the std:: on line 117 |
||
| FieldValueTuple fv("blackhole", "true"); | ||
| fvVector.push_back(fv); | ||
| m_routeTable.set(destip.to_string(), fvVector); | ||
| m_routeTable.set(destipprefix, fvVector); | ||
| return; | ||
| } | ||
| case RTN_UNICAST: | ||
|
|
@@ -72,9 +65,7 @@ void RouteSync::onMsg(int nlmsg_type, struct nl_object *obj) | |
| case RTN_MULTICAST: | ||
| case RTN_BROADCAST: | ||
| case RTN_LOCAL: | ||
| nl_addr2str(dip, ifname, MAX_ADDR_SIZE); | ||
| SWSS_LOG_INFO("%s: BUM routes aren't supported yet (%s)\n", | ||
| __FUNCTION__, ifname); | ||
| SWSS_LOG_INFO("BUM routes aren't supported yet (%s)\n", destipprefix); | ||
| return; | ||
|
|
||
| default: | ||
|
|
@@ -88,12 +79,11 @@ void RouteSync::onMsg(int nlmsg_type, struct nl_object *obj) | |
| struct nl_list_head *nhs = rtnl_route_get_nexthops(route_obj); | ||
| if (!nhs) | ||
| { | ||
| nl_addr2str(dip, ifname, MAX_ADDR_SIZE); | ||
| SWSS_LOG_INFO("%s: Nexthop list is empty for %s\n", | ||
| __FUNCTION__, ifname); | ||
| SWSS_LOG_INFO("Nexthop list is empty for %s\n", destipprefix); | ||
| return; | ||
| } | ||
|
|
||
| char ifname[IFNAMSIZ] = {0}; | ||
| for (int i = 0; i < rtnl_route_get_nnexthops(route_obj); i++) | ||
| { | ||
| struct rtnl_nexthop *nexthop = rtnl_route_nexthop_n(route_obj, i); | ||
|
|
@@ -106,12 +96,12 @@ void RouteSync::onMsg(int nlmsg_type, struct nl_object *obj) | |
| nexthops += nh.to_string(); | ||
| } | ||
|
|
||
| rtnl_link_i2name(m_link_cache, ifindex, ifname, MAX_ADDR_SIZE); | ||
| rtnl_link_i2name(m_link_cache, ifindex, ifname, IFNAMSIZ); | ||
| /* Cannot get ifname. Possibly interfaces get re-created. */ | ||
| if (!strlen(ifname)) | ||
| { | ||
| rtnl_link_alloc_cache(m_nl_sock, AF_UNSPEC, &m_link_cache); | ||
| rtnl_link_i2name(m_link_cache, ifindex, ifname, MAX_ADDR_SIZE); | ||
| rtnl_link_i2name(m_link_cache, ifindex, ifname, IFNAMSIZ); | ||
| if (!strlen(ifname)) | ||
| strcpy(ifname, "unknown"); | ||
| } | ||
|
|
@@ -129,5 +119,5 @@ void RouteSync::onMsg(int nlmsg_type, struct nl_object *obj) | |
| FieldValueTuple idx("ifname", ifnames); | ||
| fvVector.push_back(nh); | ||
| fvVector.push_back(idx); | ||
| m_routeTable.set(destip.to_string(), fvVector); | ||
| m_routeTable.set(destipprefix, fvVector); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adding nlmsg_type here to log more information