|
9 | 9 | using namespace swss;
|
10 | 10 | using namespace std;
|
11 | 11 |
|
12 |
| -FpmLink::FpmLink(unsigned short port) : |
| 12 | +void netlink_parse_rtattr(struct rtattr **tb, int max, struct rtattr *rta, |
| 13 | + int len) |
| 14 | +{ |
| 15 | + while (RTA_OK(rta, len)) |
| 16 | + { |
| 17 | + if (rta->rta_type <= max) |
| 18 | + { |
| 19 | + tb[rta->rta_type] = rta; |
| 20 | + } |
| 21 | + rta = RTA_NEXT(rta, len); |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +bool FpmLink::isRawProcessing(struct nlmsghdr *h) |
| 26 | +{ |
| 27 | + int len; |
| 28 | + short encap_type = 0; |
| 29 | + struct rtmsg *rtm; |
| 30 | + struct rtattr *tb[RTA_MAX + 1]; |
| 31 | + |
| 32 | + rtm = (struct rtmsg *)NLMSG_DATA(h); |
| 33 | + |
| 34 | + if (h->nlmsg_type != RTM_NEWROUTE && h->nlmsg_type != RTM_DELROUTE) |
| 35 | + { |
| 36 | + return false; |
| 37 | + } |
| 38 | + |
| 39 | + len = (int)(h->nlmsg_len - NLMSG_LENGTH(sizeof(struct rtmsg))); |
| 40 | + if (len < 0) |
| 41 | + { |
| 42 | + return false; |
| 43 | + } |
| 44 | + |
| 45 | + memset(tb, 0, sizeof(tb)); |
| 46 | + netlink_parse_rtattr(tb, RTA_MAX, RTM_RTA(rtm), len); |
| 47 | + |
| 48 | + if (!tb[RTA_MULTIPATH]) |
| 49 | + { |
| 50 | + if (tb[RTA_ENCAP_TYPE]) |
| 51 | + { |
| 52 | + encap_type = *(short *)RTA_DATA(tb[RTA_ENCAP_TYPE]); |
| 53 | + } |
| 54 | + } |
| 55 | + else |
| 56 | + { |
| 57 | + /* This is a multipath route */ |
| 58 | + int len; |
| 59 | + struct rtnexthop *rtnh = (struct rtnexthop *)RTA_DATA(tb[RTA_MULTIPATH]); |
| 60 | + len = (int)RTA_PAYLOAD(tb[RTA_MULTIPATH]); |
| 61 | + struct rtattr *subtb[RTA_MAX + 1]; |
| 62 | + |
| 63 | + for (;;) |
| 64 | + { |
| 65 | + if (len < (int)sizeof(*rtnh) || rtnh->rtnh_len > len) |
| 66 | + { |
| 67 | + break; |
| 68 | + } |
| 69 | + |
| 70 | + if (rtnh->rtnh_len > sizeof(*rtnh)) |
| 71 | + { |
| 72 | + memset(subtb, 0, sizeof(subtb)); |
| 73 | + netlink_parse_rtattr(subtb, RTA_MAX, RTNH_DATA(rtnh), |
| 74 | + (int)(rtnh->rtnh_len - sizeof(*rtnh))); |
| 75 | + if (subtb[RTA_ENCAP_TYPE]) |
| 76 | + { |
| 77 | + encap_type = *(uint16_t *)RTA_DATA(subtb[RTA_ENCAP_TYPE]); |
| 78 | + break; |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + if (rtnh->rtnh_len == 0) |
| 83 | + { |
| 84 | + break; |
| 85 | + } |
| 86 | + |
| 87 | + len -= NLMSG_ALIGN(rtnh->rtnh_len); |
| 88 | + rtnh = RTNH_NEXT(rtnh); |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + SWSS_LOG_INFO("Rx MsgType:%d Encap:%d", h->nlmsg_type, encap_type); |
| 93 | + |
| 94 | + if (encap_type > 0) |
| 95 | + { |
| 96 | + return true; |
| 97 | + } |
| 98 | + |
| 99 | + return false; |
| 100 | +} |
| 101 | + |
| 102 | +FpmLink::FpmLink(RouteSync *rsync, unsigned short port) : |
13 | 103 | MSG_BATCH_SIZE(256),
|
14 | 104 | m_bufSize(FPM_MAX_MSG_LEN * MSG_BATCH_SIZE),
|
15 | 105 | m_messageBuffer(NULL),
|
16 | 106 | m_pos(0),
|
17 | 107 | m_connected(false),
|
18 |
| - m_server_up(false) |
| 108 | + m_server_up(false), |
| 109 | + m_routesync(rsync) |
19 | 110 | {
|
20 | 111 | struct sockaddr_in addr;
|
21 | 112 | int true_val = 1;
|
@@ -120,12 +211,35 @@ uint64_t FpmLink::readData()
|
120 | 211 |
|
121 | 212 | if (hdr->msg_type == FPM_MSG_TYPE_NETLINK)
|
122 | 213 | {
|
123 |
| - nl_msg *msg = nlmsg_convert((nlmsghdr *)fpm_msg_data(hdr)); |
| 214 | + bool isRaw = false; |
| 215 | + |
| 216 | + nlmsghdr *nl_hdr = (nlmsghdr *)fpm_msg_data(hdr); |
| 217 | + |
| 218 | + /* |
| 219 | + * EVPN Type5 Add Routes need to be process in Raw mode as they contain |
| 220 | + * RMAC, VLAN and L3VNI information. |
| 221 | + * Where as all other route will be using rtnl api to extract information |
| 222 | + * from the netlink msg. |
| 223 | + * */ |
| 224 | + isRaw = isRawProcessing(nl_hdr); |
| 225 | + |
| 226 | + nl_msg *msg = nlmsg_convert(nl_hdr); |
124 | 227 | if (msg == NULL)
|
| 228 | + { |
125 | 229 | throw system_error(make_error_code(errc::bad_message), "Unable to convert nlmsg");
|
| 230 | + } |
126 | 231 |
|
127 | 232 | nlmsg_set_proto(msg, NETLINK_ROUTE);
|
128 |
| - NetDispatcher::getInstance().onNetlinkMessage(msg); |
| 233 | + |
| 234 | + if (isRaw) |
| 235 | + { |
| 236 | + /* EVPN Type5 Add route processing */ |
| 237 | + processRawMsg(nl_hdr); |
| 238 | + } |
| 239 | + else |
| 240 | + { |
| 241 | + NetDispatcher::getInstance().onNetlinkMessage(msg); |
| 242 | + } |
129 | 243 | nlmsg_free(msg);
|
130 | 244 | }
|
131 | 245 | start += msg_len;
|
|
0 commit comments