* Parses capabilities from buffer * * \details * Reads the capabilities from buffer. The parsed data will be * returned via the out params. * * \param [in] data Pointer to raw bgp payload data, starting at the open/cap message * \param [in] size Size of the data available to read; prevent overrun when reading * \param [in] openMessageIsSent If
| 138 | * \return ZERO is error, otherwise a positive value indicating the number of bytes read |
| 139 | */ |
| 140 | size_t OpenMsg::parseCapabilities(u_char *data, size_t size, bool openMessageIsSent, uint32_t &asn, |
| 141 | std::list<std::string> &capabilities) |
| 142 | { |
| 143 | size_t read_size = 0; |
| 144 | u_char *bufPtr = data; |
| 145 | |
| 146 | /* |
| 147 | * Loop through the capabilities (will set the 4 byte ASN) |
| 148 | */ |
| 149 | char capStr[200]; |
| 150 | open_param *param; |
| 151 | cap_param *cap; |
| 152 | |
| 153 | for (int i=0; i < size; ) { |
| 154 | param = (open_param *)bufPtr; |
| 155 | SELF_DEBUG("%s: Open param type=%d len=%d", peer_addr.c_str(), param->type, param->len); |
| 156 | |
| 157 | if (param->type != BGP_CAP_PARAM_TYPE) { |
| 158 | LOG_NOTICE("%s: Open param type %d is not supported, expected type %d", peer_addr.c_str(), |
| 159 | param->type, BGP_CAP_PARAM_TYPE); |
| 160 | } |
| 161 | |
| 162 | /* |
| 163 | * Process the capabilities if present |
| 164 | */ |
| 165 | else if (param->len >= 2 and (read_size + 2 + param->len) <= size) { |
| 166 | u_char *cap_ptr = bufPtr + 2; |
| 167 | |
| 168 | for (int c=0; c < param->len; ) { |
| 169 | cap = (cap_param *)cap_ptr; |
| 170 | SELF_DEBUG("%s: Capability code=%d len=%d", peer_addr.c_str(), cap->code, cap->len); |
| 171 | |
| 172 | /* |
| 173 | * Handle the capability |
| 174 | */ |
| 175 | switch (cap->code) { |
| 176 | case BGP_CAP_4OCTET_ASN : |
| 177 | if (cap->len == 4) { |
| 178 | memcpy(&asn, cap_ptr + 2, 4); |
| 179 | bgp::SWAP_BYTES(&asn); |
| 180 | snprintf(capStr, sizeof(capStr), "4 Octet ASN (%d)", BGP_CAP_4OCTET_ASN); |
| 181 | capabilities.push_back(capStr); |
| 182 | } else { |
| 183 | LOG_NOTICE("%s: 4 octet ASN capability length is invalid %d expected 4", peer_addr.c_str(), cap->len); |
| 184 | } |
| 185 | break; |
| 186 | |
| 187 | case BGP_CAP_ROUTE_REFRESH: |
| 188 | SELF_DEBUG("%s: supports route-refresh", peer_addr.c_str()); |
| 189 | snprintf(capStr, sizeof(capStr), "Route Refresh (%d)", BGP_CAP_ROUTE_REFRESH); |
| 190 | capabilities.push_back(capStr); |
| 191 | break; |
| 192 | |
| 193 | case BGP_CAP_ROUTE_REFRESH_ENHANCED: |
| 194 | SELF_DEBUG("%s: supports route-refresh enhanced", peer_addr.c_str()); |
| 195 | snprintf(capStr, sizeof(capStr), "Route Refresh Enhanced (%d)", BGP_CAP_ROUTE_REFRESH_ENHANCED); |
| 196 | capabilities.push_back(capStr); |
| 197 | break; |
nothing calls this directly
no test coverage detected