1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
|
// -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
// Copyright (c) 2001-2009 XORP, Inc.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License, Version 2, June
// 1991 as published by the Free Software Foundation. Redistribution
// and/or modification of this program under the terms of any other
// version of the GNU General Public License is not permitted.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
// see the GNU General Public License, Version 2, a copy of which can be
// found in the XORP LICENSE.gpl file.
//
// XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
// http://xorp.net
#ident "$XORP: xorp/pim/pim_proto_join_prune.cc,v 1.20 2009/01/05 18:31:03 jtc Exp $"
//
// PIM PIM_JOIN_PRUNE messages processing.
//
#include "pim_module.h"
#include "libxorp/xorp.h"
#include "libxorp/xlog.h"
#include "libxorp/debug.h"
#include "libxorp/ipvx.hh"
#include "pim_node.hh"
#include "pim_vif.hh"
//
// Exported variables
//
//
// Local constants definitions
//
//
// Local structures/classes, typedefs and macros
//
//
// Local variables
//
//
// Local functions prototypes
//
/**
* PimVif::pim_join_prune_recv:
* @pim_nbr: The PIM neighbor message originator (or NULL if not a neighbor).
* @src: The message source address.
* @dst: The message destination address.
* @buffer: The buffer with the message.
* @message_type: The message type (should be either %PIM_JOIN_PRUNE
* or %PIM_GRAFT.
*
* Receive PIM_JOIN_PRUNE message.
* XXX: PIM_GRAFT message has the same format as the
* PIM_JOIN_PRUNE message, hence we use the PIM_JOIN_PRUNE processing
* function to process PIM_GRAFT as well.
* TODO: for now ignore PIM_GRAFT messages logic; will need to come
* back to it later.
*
* Return value: %XORP_OK on success, otherwise %XORP_ERROR.
**/
int
PimVif::pim_join_prune_recv(PimNbr *pim_nbr, const IPvX& src,
const IPvX& dst, buffer_t *buffer,
uint8_t message_type)
{
int holdtime;
int rcvd_family;
IPvX target_nbr_addr(family());
IPvX source_addr(family()), group_addr(family());
uint8_t source_mask_len, group_mask_len;
uint8_t group_addr_reserved_flags;
int groups_n, sources_n, sources_j_n, sources_p_n;
uint8_t source_flags;
bool is_group_ignored, is_rp_entry, is_new_group;
action_jp_t action_jp;
mrt_entry_type_t mrt_entry_type;
PimJpHeader jp_header(pim_node());
//
// Parse the message
//
GET_ENCODED_UNICAST_ADDR(rcvd_family, target_nbr_addr, buffer);
// Check the target neighbor address.
// XXX: on point-to-point links we accept target_nbr_addr of all zeros
if (! (target_nbr_addr.is_unicast()
|| (is_p2p() && (target_nbr_addr == IPvX::ZERO(family()))))) {
XLOG_WARNING("RX %s from %s to %s: "
"invalid 'upstream neighbor' "
"address: %s",
PIMTYPE2ASCII(message_type),
cstring(src), cstring(dst),
cstring(target_nbr_addr));
return (XORP_ERROR);
}
BUFFER_GET_SKIP(1, buffer); // Reserved
BUFFER_GET_OCTET(groups_n, buffer);
BUFFER_GET_HOST_16(holdtime, buffer);
//
// XXX: here we should test that (groups_n > 0), but
// we should be liberal about such errors.
//
while (groups_n--) {
GET_ENCODED_GROUP_ADDR(rcvd_family, group_addr, group_mask_len,
group_addr_reserved_flags, buffer);
BUFFER_GET_HOST_16(sources_j_n, buffer);
BUFFER_GET_HOST_16(sources_p_n, buffer);
// Check the group address
is_group_ignored = true;
is_rp_entry = false;
is_new_group = true;
//
// Check the group address and mask length
//
do {
if (group_mask_len == IPvX::ip_multicast_base_address_mask_len(family())
&& (group_addr == IPvX::MULTICAST_BASE(family()))) {
// XXX: (*,*,RP) Join/Prune
is_group_ignored = false;
is_rp_entry = true;
break;
}
if (! group_addr.is_multicast()) {
XLOG_WARNING("RX %s from %s to %s: "
"invalid group address: %s",
PIMTYPE2ASCII(message_type),
cstring(src), cstring(dst),
cstring(group_addr));
is_group_ignored = true;
break;
}
if (group_addr.is_linklocal_multicast()
|| group_addr.is_interfacelocal_multicast()) {
XLOG_WARNING("RX %s from %s to %s: "
"non-routable link or interface-local "
"group address: %s",
PIMTYPE2ASCII(message_type),
cstring(src), cstring(dst),
cstring(group_addr));
is_group_ignored = true;
break;
}
if (group_mask_len != group_addr.addr_bitlen()) {
is_group_ignored = true;
XLOG_WARNING("RX %s from %s to %s: "
"invalid group mask length for group %s: %d",
PIMTYPE2ASCII(message_type),
cstring(src), cstring(dst),
cstring(group_addr),
group_mask_len);
break;
}
is_group_ignored = false;
break;
} while (false);
sources_n = sources_j_n + sources_p_n;
action_jp = ACTION_JOIN;
while (sources_n--) {
if (sources_j_n > 0) {
action_jp = ACTION_JOIN;
sources_j_n--;
} else {
action_jp = ACTION_PRUNE;
sources_p_n--;
}
GET_ENCODED_SOURCE_ADDR(rcvd_family, source_addr,
source_mask_len, source_flags, buffer);
if (is_group_ignored)
continue;
// Check the source address and mask length
if (! source_addr.is_unicast()) {
XLOG_WARNING("RX %s from %s to %s: "
"invalid source/RP address: %s",
PIMTYPE2ASCII(message_type),
cstring(src), cstring(dst),
cstring(source_addr));
continue;
}
if (source_mask_len != source_addr.addr_bitlen()) {
XLOG_WARNING("RX %s from %s to %s: "
"invalid source mask length "
"for group %s source/RP %s: %d",
PIMTYPE2ASCII(message_type),
cstring(src), cstring(dst),
cstring(group_addr),
cstring(source_addr),
source_mask_len);
continue;
}
//
// Check the source flags if they are valid.
//
if (proto_is_pimdm()) {
if (source_flags & (ESADDR_RPT_BIT | ESADDR_WC_BIT | ESADDR_S_BIT)) {
// XXX: PIM-DM does not use those flags.
XLOG_WARNING("RX %s from %s to %s: "
"invalid source/RP flags "
"while running in PIM-DM mode "
"for (%s, %s): %#x",
PIMTYPE2ASCII(message_type),
cstring(src), cstring(dst),
cstring(source_addr),
cstring(group_addr),
source_flags);
continue;
}
}
if (proto_is_pimsm()) {
if ((source_flags & ESADDR_S_BIT) != ESADDR_S_BIT) {
// Missing "Sparse bit"
XLOG_WARNING("RX %s from %s to %s: "
"missing Sparse-bit flag "
"while running in PIM-SM mode "
"for (%s, %s)",
PIMTYPE2ASCII(message_type),
cstring(src), cstring(dst),
cstring(source_addr),
cstring(group_addr));
continue;
}
}
//
// Check the source flags to find the entry type.
//
mrt_entry_type = MRT_ENTRY_UNKNOWN;
// (*,*,RP) entry
if (is_rp_entry) {
if ((source_flags & (ESADDR_RPT_BIT | ESADDR_WC_BIT))
!= (ESADDR_RPT_BIT | ESADDR_WC_BIT)) {
XLOG_WARNING("RX %s from %s to %s: "
"invalid source/RP flags "
"for (*,*,RP) RP = %s: %#x",
PIMTYPE2ASCII(message_type),
cstring(src), cstring(dst),
cstring(source_addr), source_flags);
continue;
}
mrt_entry_type = MRT_ENTRY_RP;
goto jp_entry_add_label;
}
// (*,G) entry
if ((source_flags & (ESADDR_RPT_BIT | ESADDR_WC_BIT))
== (ESADDR_RPT_BIT | ESADDR_WC_BIT)) {
//
// Check if the RP address matches. If not, silently ignore
// the (*,G) entry. However, the (S,G) and (S,G,rpt) entries
// for same group should still be processed.
//
PimRp *pim_rp = pim_node().rp_table().rp_find(group_addr);
if ((pim_rp == NULL) || (pim_rp->rp_addr() != source_addr)) {
XLOG_TRACE(pim_node().is_log_trace(),
"RX %s from %s to %s: "
"(*,G) Join/Prune entry for group %s "
"RP address does not match: "
"router RP = %s, message RP = %s",
PIMTYPE2ASCII(message_type),
cstring(src), cstring(dst),
cstring(group_addr),
pim_rp? cstring(pim_rp->rp_addr()) : "NULL",
cstring(source_addr));
continue;
}
mrt_entry_type = MRT_ENTRY_WC;
goto jp_entry_add_label;
}
// (S,G,rpt) entry
if ((source_flags & (ESADDR_RPT_BIT | ESADDR_WC_BIT))
== ESADDR_RPT_BIT) {
mrt_entry_type = MRT_ENTRY_SG_RPT;
goto jp_entry_add_label;
}
// (S,G) entry
if ((source_flags & (ESADDR_RPT_BIT | ESADDR_WC_BIT)) == 0) {
mrt_entry_type = MRT_ENTRY_SG;
goto jp_entry_add_label;
}
// Unknown entry
XLOG_WARNING("RX %s from %s to %s: "
"invalid source/RP flags for (%s, %s): %#x",
PIMTYPE2ASCII(message_type),
cstring(src), cstring(dst),
cstring(source_addr),
cstring(group_addr),
source_flags);
continue;
jp_entry_add_label:
// An the entry to the pool of entries pending commit.
// TODO: if error, then ignore the whole message??
jp_header.jp_entry_add(source_addr, group_addr,
group_mask_len, mrt_entry_type,
action_jp, holdtime, is_new_group);
is_new_group = false;
// Keep statistics per entry type
switch (mrt_entry_type) {
case MRT_ENTRY_RP:
if (action_jp == ACTION_JOIN)
++_pimstat_rx_join_rp;
else
++_pimstat_rx_prune_rp;
break;
case MRT_ENTRY_WC:
if (action_jp == ACTION_JOIN)
++_pimstat_rx_join_wc;
else
++_pimstat_rx_prune_wc;
break;
case MRT_ENTRY_SG:
if (action_jp == ACTION_JOIN)
++_pimstat_rx_join_sg;
else
++_pimstat_rx_prune_sg;
break;
case MRT_ENTRY_SG_RPT:
if (action_jp == ACTION_JOIN)
++_pimstat_rx_join_sg_rpt;
else
++_pimstat_rx_prune_sg_rpt;
break;
default:
XLOG_UNREACHABLE();
break;
}
}
}
// Commit all Join/Prune requests to the MRT
jp_header.mrt_commit(this, target_nbr_addr);
jp_header.reset();
UNUSED(pim_nbr);
return (XORP_OK);
// Various error processing
rcvlen_error:
XLOG_WARNING("RX %s from %s to %s: "
"invalid message length",
PIMTYPE2ASCII(PIM_JOIN_PRUNE),
cstring(src), cstring(dst));
++_pimstat_rx_malformed_packet;
return (XORP_ERROR);
rcvd_mask_len_error:
XLOG_WARNING("RX %s from %s to %s: "
"invalid group mask length = %d",
PIMTYPE2ASCII(PIM_JOIN_PRUNE),
cstring(src), cstring(dst),
group_mask_len);
return (XORP_ERROR);
rcvd_family_error:
XLOG_WARNING("RX %s from %s to %s: "
"invalid address family inside = %d",
PIMTYPE2ASCII(PIM_JOIN_PRUNE),
cstring(src), cstring(dst),
rcvd_family);
return (XORP_ERROR);
}
//
// Send Join/Prune message(s) to a PIM neighbor.
//
int
PimVif::pim_join_prune_send(PimNbr *pim_nbr, PimJpHeader *jp_header,
string& error_msg)
{
int ret_value = jp_header->network_commit(this, pim_nbr->primary_addr(),
error_msg);
jp_header->reset();
return (ret_value);
}
|