diff options
Diffstat (limited to 'pimd')
| -rw-r--r-- | pimd/pim6_cmd.c | 183 | ||||
| -rw-r--r-- | pimd/pim6_mroute_msg.c | 196 | ||||
| -rw-r--r-- | pimd/pim6_stubs.c | 53 | ||||
| -rw-r--r-- | pimd/pim_assert.c | 5 | ||||
| -rw-r--r-- | pimd/pim_bsm.c | 33 | ||||
| -rw-r--r-- | pimd/pim_bsm.h | 7 | ||||
| -rw-r--r-- | pimd/pim_iface.c | 9 | ||||
| -rw-r--r-- | pimd/pim_igmp.c | 27 | ||||
| -rw-r--r-- | pimd/pim_instance.h | 13 | ||||
| -rw-r--r-- | pimd/pim_join.c | 13 | ||||
| -rw-r--r-- | pimd/pim_mroute.c | 387 | ||||
| -rw-r--r-- | pimd/pim_mroute.h | 187 | ||||
| -rw-r--r-- | pimd/pim_mroute_msg.c | 239 | ||||
| -rw-r--r-- | pimd/pim_msg.c | 46 | ||||
| -rw-r--r-- | pimd/pim_msg.h | 13 | ||||
| -rw-r--r-- | pimd/pim_nb_config.c | 22 | ||||
| -rw-r--r-- | pimd/pim_nht.c | 4 | ||||
| -rw-r--r-- | pimd/pim_nht.h | 2 | ||||
| -rw-r--r-- | pimd/pim_oil.c | 19 | ||||
| -rw-r--r-- | pimd/pim_oil.h | 18 | ||||
| -rw-r--r-- | pimd/pim_pim.c | 259 | ||||
| -rw-r--r-- | pimd/pim_pim.h | 3 | ||||
| -rw-r--r-- | pimd/pim_register.c | 6 | ||||
| -rw-r--r-- | pimd/pim_register.h | 6 | ||||
| -rw-r--r-- | pimd/pim_ssmpingd.c | 10 | ||||
| -rw-r--r-- | pimd/pim_vty.c | 2 | ||||
| -rw-r--r-- | pimd/subdir.am | 4 |
27 files changed, 1134 insertions, 632 deletions
diff --git a/pimd/pim6_cmd.c b/pimd/pim6_cmd.c index e3130b1564..7b3e04fdc0 100644 --- a/pimd/pim6_cmd.c +++ b/pimd/pim6_cmd.c @@ -448,6 +448,180 @@ DEFPY (no_ipv6_pim_rp_prefix_list, return pim_process_no_rp_plist_cmd(vty, rp_str, plist); } +DEFPY (interface_ipv6_mld_join, + interface_ipv6_mld_join_cmd, + "ipv6 mld join X:X::X:X$group [X:X::X:X$source]", + IPV6_STR + IFACE_MLD_STR + "MLD join multicast group\n" + "Multicast group address\n" + "Source address\n") +{ + char xpath[XPATH_MAXLEN]; + + if (source_str) { + if (IPV6_ADDR_SAME(&source, &in6addr_any)) { + vty_out(vty, "Bad source address %s\n", source_str); + return CMD_WARNING_CONFIG_FAILED; + } + } else + source_str = "::"; + + snprintf(xpath, sizeof(xpath), FRR_GMP_JOIN_XPATH, "frr-routing:ipv6", + group_str, source_str); + + nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL); + + return nb_cli_apply_changes(vty, NULL); +} + +DEFPY (interface_no_ipv6_mld_join, + interface_no_ipv6_mld_join_cmd, + "no ipv6 mld join X:X::X:X$group [X:X::X:X$source]", + NO_STR + IPV6_STR + IFACE_MLD_STR + "MLD join multicast group\n" + "Multicast group address\n" + "Source address\n") +{ + char xpath[XPATH_MAXLEN]; + + if (source_str) { + if (IPV6_ADDR_SAME(&source, &in6addr_any)) { + vty_out(vty, "Bad source address %s\n", source_str); + return CMD_WARNING_CONFIG_FAILED; + } + } else + source_str = "::"; + + snprintf(xpath, sizeof(xpath), FRR_GMP_JOIN_XPATH, "frr-routing:ipv6", + group_str, source_str); + + nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL); + + return nb_cli_apply_changes(vty, NULL); +} + +DEFPY (interface_ipv6_mld, + interface_ipv6_mld_cmd, + "ipv6 mld", + IPV6_STR + IFACE_MLD_STR) +{ + nb_cli_enqueue_change(vty, "./enable", NB_OP_MODIFY, "true"); + + return nb_cli_apply_changes(vty, FRR_GMP_INTERFACE_XPATH, + "frr-routing:ipv6"); +} + +DEFPY (interface_no_ipv6_mld, + interface_no_ipv6_mld_cmd, + "no ipv6 mld", + NO_STR + IPV6_STR + IFACE_MLD_STR) +{ + const struct lyd_node *pim_enable_dnode; + char pim_if_xpath[XPATH_MAXLEN + 64]; + + snprintf(pim_if_xpath, sizeof(pim_if_xpath), + "%s/frr-pim:pim/address-family[address-family='%s']", + VTY_CURR_XPATH, "frr-routing:ipv6"); + + pim_enable_dnode = yang_dnode_getf(vty->candidate_config->dnode, + FRR_PIM_ENABLE_XPATH, VTY_CURR_XPATH, + "frr-routing:ipv6"); + if (!pim_enable_dnode) { + nb_cli_enqueue_change(vty, pim_if_xpath, NB_OP_DESTROY, NULL); + nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL); + } else { + if (!yang_dnode_get_bool(pim_enable_dnode, ".")) { + nb_cli_enqueue_change(vty, pim_if_xpath, NB_OP_DESTROY, + NULL); + nb_cli_enqueue_change(vty, ".", NB_OP_DESTROY, NULL); + } else + nb_cli_enqueue_change(vty, "./enable", NB_OP_MODIFY, + "false"); + } + + return nb_cli_apply_changes(vty, FRR_GMP_INTERFACE_XPATH, + "frr-routing:ipv6"); +} + +DEFPY (interface_ipv6_mld_version, + interface_ipv6_mld_version_cmd, + "ipv6 mld version (1-2)$version", + IPV6_STR + IFACE_MLD_STR + "MLD version\n" + "MLD version number\n") +{ + nb_cli_enqueue_change(vty, "./enable", NB_OP_MODIFY, "true"); + nb_cli_enqueue_change(vty, "./mld-version", NB_OP_MODIFY, version_str); + + return nb_cli_apply_changes(vty, FRR_GMP_INTERFACE_XPATH, + "frr-routing:ipv6"); +} + +DEFPY (interface_no_ipv6_mld_version, + interface_no_ipv6_mld_version_cmd, + "no ipv6 mld version [(1-2)]", + NO_STR + IPV6_STR + IFACE_MLD_STR + "MLD version\n" + "MLD version number\n") +{ + nb_cli_enqueue_change(vty, "./mld-version", NB_OP_DESTROY, NULL); + + return nb_cli_apply_changes(vty, FRR_GMP_INTERFACE_XPATH, + "frr-routing:ipv6"); +} + +DEFPY (interface_ipv6_mld_query_interval, + interface_ipv6_mld_query_interval_cmd, + "ipv6 mld query-interval (1-65535)$q_interval", + IPV6_STR + IFACE_MLD_STR + IFACE_MLD_QUERY_INTERVAL_STR + "Query interval in seconds\n") +{ + const struct lyd_node *pim_enable_dnode; + + pim_enable_dnode = yang_dnode_getf(vty->candidate_config->dnode, + FRR_PIM_ENABLE_XPATH, VTY_CURR_XPATH, + "frr-routing:ipv6"); + if (!pim_enable_dnode) { + nb_cli_enqueue_change(vty, "./enable", NB_OP_MODIFY, "true"); + } else { + if (!yang_dnode_get_bool(pim_enable_dnode, ".")) + nb_cli_enqueue_change(vty, "./enable", NB_OP_MODIFY, + "true"); + } + + nb_cli_enqueue_change(vty, "./query-interval", NB_OP_MODIFY, + q_interval_str); + + return nb_cli_apply_changes(vty, FRR_GMP_INTERFACE_XPATH, + "frr-routing:ipv6"); +} + +DEFPY (interface_no_ipv6_mld_query_interval, + interface_no_ipv6_mld_query_interval_cmd, + "no ipv6 mld query-interval [(1-65535)]", + NO_STR + IPV6_STR + IFACE_MLD_STR + IFACE_MLD_QUERY_INTERVAL_STR + IGNORED_IN_NO_STR) +{ + nb_cli_enqueue_change(vty, "./query-interval", NB_OP_DESTROY, NULL); + + return nb_cli_apply_changes(vty, FRR_GMP_INTERFACE_XPATH, + "frr-routing:ipv6"); +} + void pim_cmd_init(void) { if_cmd_init(pim_interface_config_write); @@ -491,4 +665,13 @@ void pim_cmd_init(void) install_element(VRF_NODE, &ipv6_pim_rp_prefix_list_cmd); install_element(CONFIG_NODE, &no_ipv6_pim_rp_prefix_list_cmd); install_element(VRF_NODE, &no_ipv6_pim_rp_prefix_list_cmd); + install_element(INTERFACE_NODE, &interface_ipv6_mld_cmd); + install_element(INTERFACE_NODE, &interface_no_ipv6_mld_cmd); + install_element(INTERFACE_NODE, &interface_ipv6_mld_join_cmd); + install_element(INTERFACE_NODE, &interface_no_ipv6_mld_join_cmd); + install_element(INTERFACE_NODE, &interface_ipv6_mld_version_cmd); + install_element(INTERFACE_NODE, &interface_no_ipv6_mld_version_cmd); + install_element(INTERFACE_NODE, &interface_ipv6_mld_query_interval_cmd); + install_element(INTERFACE_NODE, + &interface_no_ipv6_mld_query_interval_cmd); } diff --git a/pimd/pim6_mroute_msg.c b/pimd/pim6_mroute_msg.c new file mode 100644 index 0000000000..f34fa5965a --- /dev/null +++ b/pimd/pim6_mroute_msg.c @@ -0,0 +1,196 @@ +/* + * PIM for Quagga + * Copyright (C) 2022 Dell Technologies Ltd + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; see the file COPYING; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <zebra.h> +#include "log.h" +#include "privs.h" +#include "if.h" +#include "prefix.h" +#include "vty.h" +#include "plist.h" +#include "sockopt.h" +#include "lib_errors.h" +#include "lib/network.h" + +#include "pimd.h" +#include "pim_mroute.h" +#include "pim_oil.h" +#include "pim_str.h" +#include "pim_time.h" +#include "pim_iface.h" +#include "pim_macro.h" +#include "pim_rp.h" +#include "pim_oil.h" +#include "pim_ssm.h" +#include "pim_sock.h" + +int pim_mroute_set(struct pim_instance *pim, int enable) +{ + int err; + int opt, data; + socklen_t data_len = sizeof(data); + static const struct sock_filter filter[] = { + BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 0), + BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0, 0, 1), + BPF_STMT(BPF_RET | BPF_K, 0xffff), + BPF_STMT(BPF_RET | BPF_K, 0), + }; + + static const struct sock_fprog bpf = { + .len = array_size(filter), + .filter = (struct sock_filter *)filter, + }; + + /* + * We need to create the VRF table for the pim mroute_socket + */ + if (pim->vrf->vrf_id != VRF_DEFAULT) { + frr_with_privs (&pimd_privs) { + + data = pim->vrf->data.l.table_id; + err = setsockopt(pim->mroute_socket, PIM_IPPROTO, + MRT6_TABLE, &data, data_len); + if (err) { + zlog_warn( + "%s %s: failure: setsockopt(fd=%d,PIM_IPPROTO, MRT6_TABLE=%d): errno=%d: %s", + __FILE__, __func__, pim->mroute_socket, + data, errno, safe_strerror(errno)); + return -1; + } + } + } + + frr_with_privs (&pimd_privs) { + opt = enable ? MRT6_INIT : MRT6_DONE; + /* + * *BSD *cares* about what value we pass down + * here + */ + data = 1; + err = setsockopt(pim->mroute_socket, PIM_IPPROTO, opt, &data, + data_len); + if (err) { + zlog_warn( + "%s %s: failure: setsockopt(fd=%d,PIM_IPPROTO,%s=%d): errno=%d: %s", + __FILE__, __func__, pim->mroute_socket, + enable ? "MRT6_INIT" : "MRT6_DONE", data, errno, + safe_strerror(errno)); + return -1; + } + } + + if (enable) { + /* Linux and Solaris IPV6_PKTINFO */ + data = 1; + if (setsockopt(pim->mroute_socket, PIM_IPPROTO, IPV6_RECVPKTINFO, + &data, data_len)) { + zlog_warn( + "Could not set IPV6_PKTINFO on socket fd=%d: errno=%d: %s", + pim->mroute_socket, errno, + safe_strerror(errno)); + } + } + + setsockopt_so_recvbuf(pim->mroute_socket, 1024 * 1024 * 8); + + if (set_nonblocking (pim->mroute_socket) < 0) { + zlog_warn( + "Could not set non blocking on socket fd=%d: errno=%d: %s", + pim->mroute_socket, errno, + safe_strerror(errno)); + } + + if (enable) { +#if defined linux + int upcalls = MRT6MSG_WRMIFWHOLE; + opt = MRT6_PIM; + + err = setsockopt(pim->mroute_socket, PIM_IPPROTO, opt, &upcalls, + sizeof(upcalls)); + if (err) { + zlog_warn( + "Failure to register for WHOLE and WRONGMIF upcalls %d %s", + errno, safe_strerror(errno)); + return -1; + } +#else + zlog_warn( + "PIM-SM will not work properly on this platform, until the ability to receive the WHOLEPKT upcall"); +#endif + if (setsockopt(pim->mroute_socket, SOL_SOCKET, SO_ATTACH_FILTER, &bpf, sizeof(bpf))) { + zlog_warn("Failure to attach SO_ATTACH_FILTER on fd %d: %d %s", + pim->mroute_socket, errno, safe_strerror(errno)); + } + } + + return 0; +} +static const char *const mrt6msgtype2str[MRT6MSG_WRMIFWHOLE + 1] = { + "<unknown_upcall?>", "NOCACHE", "WRONGMIF", "WHOLEPKT", "WRMIFWHOLE"}; + +int pim_mroute_msg(struct pim_instance *pim, const char *buf, + size_t buf_size, ifindex_t ifindex) +{ + struct interface *ifp; + const struct ip6_hdr *ip6_hdr; + const struct mrt6msg *msg; + + if (buf_size < (int)sizeof(struct ip6_hdr)) + return 0; + + ip6_hdr = (const struct ip6_hdr *)buf; + + if ((ip6_hdr->ip6_vfc & 0xf) == 0) { + msg = (const struct mrt6msg *)buf; + + ifp = pim_if_find_by_vif_index(pim, msg->im6_mif); + + if (!ifp) + return 0; + if (PIM_DEBUG_MROUTE) { + zlog_debug( + "%s: pim kernel upcall %s type=%d ip_p=%d from fd=%d for (S,G)=(%pI6,%pI6) on %s mifi=%d size=%ld", + __func__, mrt6msgtype2str[msg->im6_msgtype], + msg->im6_msgtype, ip6_hdr->ip6_nxt, + pim->mroute_socket, &msg->im6_src, + &msg->im6_dst, ifp->name, msg->im6_mif, + (long int)buf_size); + } + + switch (msg->im6_msgtype) { + case MRT6MSG_WRONGMIF: + return pim_mroute_msg_wrongvif(pim->mroute_socket, ifp, + msg); + case MRT6MSG_NOCACHE: + return pim_mroute_msg_nocache(pim->mroute_socket, ifp, + msg); + case MRT6MSG_WHOLEPKT: + return pim_mroute_msg_wholepkt(pim->mroute_socket, ifp, + (const char *)msg); + case MRT6MSG_WRMIFWHOLE: + return pim_mroute_msg_wrvifwhole( + pim->mroute_socket, ifp, (const char *)msg); + default: + break; + } + } + + return 0; +} + diff --git a/pimd/pim6_stubs.c b/pimd/pim6_stubs.c index e689c7aca4..818b137abf 100644 --- a/pimd/pim6_stubs.c +++ b/pimd/pim6_stubs.c @@ -54,70 +54,67 @@ void zclient_lookup_free(void) } /* - * packet handling + * PIM register */ -int pim_msg_send(int fd, pim_addr src, pim_addr dst, uint8_t *pim_msg, - int pim_msg_size, const char *ifname) -{ - return 0; -} - -int pim_hello_send(struct interface *ifp, uint16_t holdtime) +void pim_register_join(struct pim_upstream *up) { - return -1; } -void pim_hello_restart_now(struct interface *ifp) +void pim_null_register_send(struct pim_upstream *up) { } -void pim_hello_restart_triggered(struct interface *ifp) +void pim_reg_del_on_couldreg_fail(struct interface *ifp) { } -int pim_sock_add(struct interface *ifp) +bool pim_bsm_new_nbr_fwd(struct pim_neighbor *neigh, struct interface *ifp) { - return -1; + return false; } -void pim_sock_delete(struct interface *ifp, const char *delete_message) +void pim_bsm_proc_free(struct pim_instance *pim) { } -/* - * PIM register - */ -void pim_register_join(struct pim_upstream *up) +void pim_bsm_proc_init(struct pim_instance *pim) { } -void pim_null_register_send(struct pim_upstream *up) +struct bsgrp_node *pim_bsm_get_bsgrp_node(struct bsm_scope *scope, + struct prefix *grp) { + return NULL; } -void pim_reg_del_on_couldreg_fail(struct interface *ifp) +void pim_bsm_write_config(struct vty *vty, struct interface *ifp) { } -bool pim_bsm_new_nbr_fwd(struct pim_neighbor *neigh, struct interface *ifp) +int pim_bsm_process(struct interface *ifp, pim_sgaddr *sg, uint8_t *buf, + uint32_t buf_size, bool no_fwd) { - return false; + return 0; } -void pim_bsm_proc_free(struct pim_instance *pim) +void pim_register_send(const uint8_t *buf, int buf_size, pim_addr src, + struct pim_rpf *rpg, int null_register, + struct pim_upstream *up) { } -void pim_bsm_proc_init(struct pim_instance *pim) +void pim_register_stop_send(struct interface *ifp, pim_sgaddr *sg, pim_addr src, + pim_addr originator) { } -struct bsgrp_node *pim_bsm_get_bsgrp_node(struct bsm_scope *scope, - struct prefix *grp) +int pim_register_recv(struct interface *ifp, pim_addr dest_addr, + pim_addr src_addr, uint8_t *tlv_buf, int tlv_buf_size) { - return NULL; + return 0; } -void pim_bsm_write_config(struct vty *vty, struct interface *ifp) +int pim_register_stop_recv(struct interface *ifp, uint8_t *buf, int buf_size) { + return 0; } diff --git a/pimd/pim_assert.c b/pimd/pim_assert.c index e7fff4db6f..cbd44388c1 100644 --- a/pimd/pim_assert.c +++ b/pimd/pim_assert.c @@ -338,6 +338,7 @@ int pim_assert_build_msg(uint8_t *pim_msg, int buf_size, struct interface *ifp, uint32_t metric_preference, uint32_t route_metric, uint32_t rpt_bit_flag) { + struct pim_interface *pim_ifp = ifp->info; uint8_t *buf_pastend = pim_msg + buf_size; uint8_t *pim_msg_curr; int pim_msg_size; @@ -380,7 +381,9 @@ int pim_assert_build_msg(uint8_t *pim_msg, int buf_size, struct interface *ifp, Add PIM header */ pim_msg_size = pim_msg_curr - pim_msg; - pim_msg_build_header(pim_msg, pim_msg_size, PIM_MSG_TYPE_ASSERT, false); + pim_msg_build_header(pim_ifp->primary_address, + qpim_all_pim_routers_addr, pim_msg, pim_msg_size, + PIM_MSG_TYPE_ASSERT, false); return pim_msg_size; } diff --git a/pimd/pim_bsm.c b/pimd/pim_bsm.c index d2e299a007..0e91773be7 100644 --- a/pimd/pim_bsm.c +++ b/pimd/pim_bsm.c @@ -718,6 +718,7 @@ static bool pim_bsm_send_intf(uint8_t *buf, int len, struct interface *ifp, static bool pim_bsm_frag_send(uint8_t *buf, uint32_t len, struct interface *ifp, uint32_t pim_mtu, pim_addr dst_addr, bool no_fwd) { + struct pim_interface *pim_ifp = ifp->info; struct bsmmsg_grpinfo *grpinfo, *curgrp; uint8_t *firstgrp_ptr; uint8_t *pkt; @@ -836,9 +837,10 @@ static bool pim_bsm_frag_send(uint8_t *buf, uint32_t len, struct interface *ifp, < (PIM_BSM_GRP_LEN + PIM_BSM_RP_LEN))) { /* No space to fit in more rp, send this pkt */ this_pkt_len = pim_mtu - this_pkt_rem; - pim_msg_build_header(pak_start, this_pkt_len, - PIM_MSG_TYPE_BOOTSTRAP, - no_fwd); + pim_msg_build_header( + pim_ifp->primary_address, dst_addr, + pak_start, this_pkt_len, + PIM_MSG_TYPE_BOOTSTRAP, no_fwd); pim_bsm_send_intf(pak_start, this_pkt_len, ifp, dst_addr); @@ -873,7 +875,8 @@ static bool pim_bsm_frag_send(uint8_t *buf, uint32_t len, struct interface *ifp, /* Send if we have any unsent packet */ if (pak_pending) { this_pkt_len = pim_mtu - this_pkt_rem; - pim_msg_build_header(pak_start, this_pkt_len, + pim_msg_build_header(pim_ifp->primary_address, dst_addr, + pak_start, this_pkt_len, PIM_MSG_TYPE_BOOTSTRAP, no_fwd); pim_bsm_send_intf(pak_start, (pim_mtu - this_pkt_rem), ifp, dst_addr); @@ -920,7 +923,8 @@ static void pim_bsm_fwd_whole_sz(struct pim_instance *pim, uint8_t *buf, zlog_debug("%s: pim_bsm_frag_send returned %s", __func__, ret ? "TRUE" : "FALSE"); } else { - pim_msg_build_header(buf, len, PIM_MSG_TYPE_BOOTSTRAP, + pim_msg_build_header(pim_ifp->primary_address, dst_addr, + buf, len, PIM_MSG_TYPE_BOOTSTRAP, no_fwd); if (!pim_bsm_send_intf(buf, len, ifp, dst_addr)) { if (PIM_DEBUG_BSM) @@ -999,7 +1003,8 @@ bool pim_bsm_new_nbr_fwd(struct pim_neighbor *neigh, struct interface *ifp) } } else { /* Pim header needs to be constructed */ - pim_msg_build_header(bsfrag->data, bsfrag->size, + pim_msg_build_header(pim_ifp->primary_address, dst_addr, + bsfrag->data, bsfrag->size, PIM_MSG_TYPE_BOOTSTRAP, no_fwd); ret = pim_bsm_send_intf(bsfrag->data, bsfrag->size, ifp, dst_addr); @@ -1271,7 +1276,7 @@ static bool pim_bsm_parse_install_g2rp(struct bsm_scope *scope, uint8_t *buf, return true; } -int pim_bsm_process(struct interface *ifp, struct ip *ip_hdr, uint8_t *buf, +int pim_bsm_process(struct interface *ifp, pim_sgaddr *sg, uint8_t *buf, uint32_t buf_size, bool no_fwd) { struct bsm_hdr *bshdr; @@ -1371,7 +1376,7 @@ int pim_bsm_process(struct interface *ifp, struct ip *ip_hdr, uint8_t *buf, } #if PIM_IPV == 4 - if (ip_hdr->ip_dst.s_addr == qpim_all_pim_routers_addr.s_addr) + if (!pim_addr_cmp(sg->grp, qpim_all_pim_routers_addr)) #else if (0) #endif @@ -1380,18 +1385,16 @@ int pim_bsm_process(struct interface *ifp, struct ip *ip_hdr, uint8_t *buf, * match RPF towards the BSR's IP address, or they have * no-forward set */ - if (!no_fwd - && !pim_nht_bsr_rpf_check(pim, bshdr->bsr_addr.addr, ifp, - ip_hdr->ip_src)) { + if (!no_fwd && !pim_nht_bsr_rpf_check(pim, bshdr->bsr_addr.addr, + ifp, sg->src)) { if (PIM_DEBUG_BSM) zlog_debug( - "BSM check: RPF to BSR %s is not %pI4%%%s", - bsr_str, &ip_hdr->ip_src, ifp->name); + "BSM check: RPF to BSR %s is not %pPA%%%s", + bsr_str, &sg->src, ifp->name); pim->bsm_dropped++; return -1; } - } else if (if_address_is_local(&ip_hdr->ip_dst, AF_INET, - pim->vrf->vrf_id)) { + } else if (if_address_is_local(&sg->grp, PIM_AF, pim->vrf->vrf_id)) { /* Unicast BSM received - if ucast bsm not enabled on * the interface, drop it */ diff --git a/pimd/pim_bsm.h b/pimd/pim_bsm.h index fceabef9e6..910067109e 100644 --- a/pimd/pim_bsm.h +++ b/pimd/pim_bsm.h @@ -207,11 +207,8 @@ void pim_bsm_proc_init(struct pim_instance *pim); void pim_bsm_proc_free(struct pim_instance *pim); void pim_bsm_clear(struct pim_instance *pim); void pim_bsm_write_config(struct vty *vty, struct interface *ifp); -int pim_bsm_process(struct interface *ifp, - struct ip *ip_hdr, - uint8_t *buf, - uint32_t buf_size, - bool no_fwd); +int pim_bsm_process(struct interface *ifp, pim_sgaddr *sg, uint8_t *buf, + uint32_t buf_size, bool no_fwd); bool pim_bsm_new_nbr_fwd(struct pim_neighbor *neigh, struct interface *ifp); struct bsgrp_node *pim_bsm_get_bsgrp_node(struct bsm_scope *scope, struct prefix *grp); diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c index 98fa4c4882..4470d05663 100644 --- a/pimd/pim_iface.c +++ b/pimd/pim_iface.c @@ -187,9 +187,7 @@ struct pim_interface *pim_if_new(struct interface *ifp, bool igmp, bool pim, ifp->info = pim_ifp; -#if PIM_IPV == 4 pim_sock_reset(ifp); -#endif pim_if_add_vif(ifp, ispimreg, is_vxlan_term); pim_ifp->pim->mcast_if_count++; @@ -1282,6 +1280,7 @@ static int igmp_join_sock(const char *ifname, ifindex_t ifindex, return join_fd; } +#if PIM_IPV == 4 static struct gm_join *igmp_join_new(struct interface *ifp, struct in_addr group_addr, struct in_addr source_addr) @@ -1320,7 +1319,9 @@ static struct gm_join *igmp_join_new(struct interface *ifp, return ij; } +#endif /* PIM_IPV == 4 */ +#if PIM_IPV == 4 ferr_r pim_if_igmp_join_add(struct interface *ifp, struct in_addr group_addr, struct in_addr source_addr) { @@ -1362,7 +1363,7 @@ ferr_r pim_if_igmp_join_add(struct interface *ifp, struct in_addr group_addr, return ferr_ok(); } - +#endif /* PIM_IPV == 4 */ int pim_if_igmp_join_del(struct interface *ifp, struct in_addr group_addr, struct in_addr source_addr) @@ -1748,7 +1749,6 @@ static int pim_ifp_down(struct interface *ifp) */ pim_if_addr_del_all(ifp); -#if PIM_IPV == 4 /* pim_sock_delete() closes the socket, stops read and timer threads, @@ -1757,7 +1757,6 @@ static int pim_ifp_down(struct interface *ifp) if (ifp->info) { pim_sock_delete(ifp, "link down"); } -#endif } if (ifp->info) { diff --git a/pimd/pim_igmp.c b/pimd/pim_igmp.c index aa6b30c624..57c4cdc470 100644 --- a/pimd/pim_igmp.c +++ b/pimd/pim_igmp.c @@ -131,12 +131,27 @@ void igmp_source_forward_reevaluate_all(struct pim_instance *pim) struct listnode *srcnode; struct gm_source *src; - /* scan group sources */ - for (ALL_LIST_ELEMENTS_RO(grp->group_source_list, - srcnode, src)) { - igmp_source_forward_reevaluate_one(pim, src); - } /* scan group sources */ - } /* scan igmp groups */ + /* + * RFC 4604 + * section 2.2.1 + * EXCLUDE mode does not apply to SSM addresses, + * and an SSM-aware router will ignore + * MODE_IS_EXCLUDE and CHANGE_TO_EXCLUDE_MODE + * requests in the SSM range. + */ + if (pim_is_grp_ssm(pim, grp->group_addr) && + grp->group_filtermode_isexcl) { + igmp_group_delete(grp); + } else { + /* scan group sources */ + for (ALL_LIST_ELEMENTS_RO( + grp->group_source_list, srcnode, + src)) { + igmp_source_forward_reevaluate_one(pim, + src); + } /* scan group sources */ + } + } /* scan igmp groups */ RB_FOREACH_SAFE (ch, pim_ifchannel_rb, &pim_ifp->ifchannel_rb, ch_temp) { diff --git a/pimd/pim_instance.h b/pimd/pim_instance.h index 4ac9ef7f51..f8323deda0 100644 --- a/pimd/pim_instance.h +++ b/pimd/pim_instance.h @@ -30,18 +30,7 @@ #include "pim_vxlan_instance.h" #include "pim_oil.h" #include "pim_upstream.h" - -#if defined(HAVE_LINUX_MROUTE_H) -#include <linux/mroute.h> -#else -/* - Below: from <linux/mroute.h> -*/ - -#ifndef MAXVIFS -#define MAXVIFS (256) -#endif -#endif +#include "pim_mroute.h" enum pim_spt_switchover { PIM_SPT_IMMEDIATE, diff --git a/pimd/pim_join.c b/pimd/pim_join.c index 2c11d5d13f..88078dd366 100644 --- a/pimd/pim_join.c +++ b/pimd/pim_join.c @@ -488,7 +488,9 @@ int pim_joinprune_send(struct pim_rpf *rpf, struct list *groups) group_size = pim_msg_get_jp_group_size(group->sources); if (group_size > packet_left) { - pim_msg_build_header(pim_msg, packet_size, + pim_msg_build_header(pim_ifp->primary_address, + qpim_all_pim_routers_addr, pim_msg, + packet_size, PIM_MSG_TYPE_JOIN_PRUNE, false); if (pim_msg_send(pim_ifp->pim_sock_fd, pim_ifp->primary_address, @@ -544,7 +546,9 @@ int pim_joinprune_send(struct pim_rpf *rpf, struct list *groups) grp = (struct pim_jp_groups *)curr_ptr; if (packet_left < sizeof(struct pim_jp_groups) || msg->num_groups == 255) { - pim_msg_build_header(pim_msg, packet_size, + pim_msg_build_header(pim_ifp->primary_address, + qpim_all_pim_routers_addr, pim_msg, + packet_size, PIM_MSG_TYPE_JOIN_PRUNE, false); if (pim_msg_send(pim_ifp->pim_sock_fd, pim_ifp->primary_address, @@ -564,8 +568,9 @@ int pim_joinprune_send(struct pim_rpf *rpf, struct list *groups) if (!new_packet) { // msg->num_groups = htons (msg->num_groups); - pim_msg_build_header(pim_msg, packet_size, - PIM_MSG_TYPE_JOIN_PRUNE, false); + pim_msg_build_header( + pim_ifp->primary_address, qpim_all_pim_routers_addr, + pim_msg, packet_size, PIM_MSG_TYPE_JOIN_PRUNE, false); if (pim_msg_send(pim_ifp->pim_sock_fd, pim_ifp->primary_address, qpim_all_pim_routers_addr, pim_msg, packet_size, diff --git a/pimd/pim_mroute.c b/pimd/pim_mroute.c index bce319b3ad..7fc4f12d27 100644 --- a/pimd/pim_mroute.c +++ b/pimd/pim_mroute.c @@ -43,121 +43,19 @@ #include "pim_ssm.h" #include "pim_sock.h" #include "pim_vxlan.h" +#include "pim_msg.h" static void mroute_read_on(struct pim_instance *pim); -static int pim_mroute_set(struct pim_instance *pim, int enable) -{ - int err; - int opt, data; - socklen_t data_len = sizeof(data); - long flags; - - /* - * We need to create the VRF table for the pim mroute_socket - */ - if (pim->vrf->vrf_id != VRF_DEFAULT) { - frr_with_privs(&pimd_privs) { - - data = pim->vrf->data.l.table_id; - err = setsockopt(pim->mroute_socket, IPPROTO_IP, - MRT_TABLE, - &data, data_len); - if (err) { - zlog_warn( - "%s %s: failure: setsockopt(fd=%d,IPPROTO_IP, MRT_TABLE=%d): errno=%d: %s", - __FILE__, __func__, pim->mroute_socket, - data, errno, safe_strerror(errno)); - return -1; - } - - } - } - - frr_with_privs(&pimd_privs) { - opt = enable ? MRT_INIT : MRT_DONE; - /* - * *BSD *cares* about what value we pass down - * here - */ - data = 1; - err = setsockopt(pim->mroute_socket, IPPROTO_IP, - opt, &data, data_len); - if (err) { - zlog_warn( - "%s %s: failure: setsockopt(fd=%d,IPPROTO_IP,%s=%d): errno=%d: %s", - __FILE__, __func__, pim->mroute_socket, - enable ? "MRT_INIT" : "MRT_DONE", data, errno, - safe_strerror(errno)); - return -1; - } - } - -#if defined(HAVE_IP_PKTINFO) - if (enable) { - /* Linux and Solaris IP_PKTINFO */ - data = 1; - if (setsockopt(pim->mroute_socket, IPPROTO_IP, IP_PKTINFO, - &data, data_len)) { - zlog_warn( - "Could not set IP_PKTINFO on socket fd=%d: errno=%d: %s", - pim->mroute_socket, errno, - safe_strerror(errno)); - } - } -#endif - - setsockopt_so_recvbuf(pim->mroute_socket, 1024 * 1024 * 8); - - flags = fcntl(pim->mroute_socket, F_GETFL, 0); - if (flags < 0) { - zlog_warn("Could not get flags on socket fd:%d %d %s", - pim->mroute_socket, errno, safe_strerror(errno)); - close(pim->mroute_socket); - return -1; - } - if (fcntl(pim->mroute_socket, F_SETFL, flags | O_NONBLOCK)) { - zlog_warn("Could not set O_NONBLOCK on socket fd:%d %d %s", - pim->mroute_socket, errno, safe_strerror(errno)); - close(pim->mroute_socket); - return -1; - } - - if (enable) { -#if defined linux - int upcalls = IGMPMSG_WRVIFWHOLE; - opt = MRT_PIM; - - err = setsockopt(pim->mroute_socket, IPPROTO_IP, opt, &upcalls, - sizeof(upcalls)); - if (err) { - zlog_warn( - "Failure to register for VIFWHOLE and WRONGVIF upcalls %d %s", - errno, safe_strerror(errno)); - return -1; - } -#else - zlog_warn( - "PIM-SM will not work properly on this platform, until the ability to receive the WRVIFWHOLE upcall"); -#endif - } - - return 0; -} - -#if PIM_IPV == 4 -static const char *const igmpmsgtype2str[IGMPMSG_WRVIFWHOLE + 1] = { - "<unknown_upcall?>", "NOCACHE", "WRONGVIF", "WHOLEPKT", "WRVIFWHOLE"}; -static int pim_mroute_msg_nocache(int fd, struct interface *ifp, - const struct igmpmsg *msg) +int pim_mroute_msg_nocache(int fd, struct interface *ifp, const kernmsg *msg) { struct pim_interface *pim_ifp = ifp->info; struct pim_upstream *up; struct pim_rpf *rpg; pim_sgaddr sg; - rpg = pim_ifp ? RP(pim_ifp->pim, msg->im_dst) : NULL; + rpg = pim_ifp ? RP(pim_ifp->pim, msg->msg_im_dst) : NULL; /* * If the incoming interface is unknown OR * the Interface type is SSM we don't need to @@ -176,7 +74,7 @@ static int pim_mroute_msg_nocache(int fd, struct interface *ifp, * If we've received a multicast packet that isn't connected to * us */ - if (!pim_if_connected_to_source(ifp, msg->im_src)) { + if (!pim_if_connected_to_source(ifp, msg->msg_im_src)) { if (PIM_DEBUG_MROUTE_DETAIL) zlog_debug( "%s: Received incoming packet that doesn't originate on our seg", @@ -185,13 +83,14 @@ static int pim_mroute_msg_nocache(int fd, struct interface *ifp, } memset(&sg, 0, sizeof(sg)); - sg.src = msg->im_src; - sg.grp = msg->im_dst; + sg.src = msg->msg_im_src; + sg.grp = msg->msg_im_dst; if (!(PIM_I_am_DR(pim_ifp))) { if (PIM_DEBUG_MROUTE_DETAIL) - zlog_debug("%s: Interface is not the DR blackholing incoming traffic for %pSG", - __func__, &sg); + zlog_debug( + "%s: Interface is not the DR blackholing incoming traffic for %pSG", + __func__, &sg); /* * We are not the DR, but we are still receiving packets @@ -238,22 +137,21 @@ static int pim_mroute_msg_nocache(int fd, struct interface *ifp, return 0; } -static int pim_mroute_msg_wholepkt(int fd, struct interface *ifp, - const char *buf) +int pim_mroute_msg_wholepkt(int fd, struct interface *ifp, const char *buf) { struct pim_interface *pim_ifp; pim_sgaddr sg; struct pim_rpf *rpg; - const struct ip *ip_hdr; + const ipv_hdr *ip_hdr; struct pim_upstream *up; pim_ifp = ifp->info; - ip_hdr = (const struct ip *)buf; + ip_hdr = (const ipv_hdr *)buf; memset(&sg, 0, sizeof(sg)); - sg.src = ip_hdr->ip_src; - sg.grp = ip_hdr->ip_dst; + sg.src = IPV_SRC(ip_hdr); + sg.grp = IPV_DST(ip_hdr); up = pim_upstream_find(pim_ifp->pim, &sg); if (!up) { @@ -268,8 +166,9 @@ static int pim_mroute_msg_wholepkt(int fd, struct interface *ifp, __func__, NULL); if (!up) { if (PIM_DEBUG_MROUTE) - zlog_debug("%s: Unable to create upstream information for %pSG", - __func__, &sg); + zlog_debug( + "%s: Unable to create upstream information for %pSG", + __func__, &sg); return 0; } pim_upstream_keep_alive_timer_start( @@ -283,8 +182,9 @@ static int pim_mroute_msg_wholepkt(int fd, struct interface *ifp, return 0; } if (PIM_DEBUG_MROUTE_DETAIL) { - zlog_debug("%s: Unable to find upstream channel WHOLEPKT%pSG", - __func__, &sg); + zlog_debug( + "%s: Unable to find upstream channel WHOLEPKT%pSG", + __func__, &sg); } return 0; } @@ -314,8 +214,9 @@ static int pim_mroute_msg_wholepkt(int fd, struct interface *ifp, if (!up->t_rs_timer) { if (pim_is_grp_ssm(pim_ifp->pim, sg.grp)) { if (PIM_DEBUG_PIM_REG) - zlog_debug("%pSG register forward skipped as group is SSM", - &sg); + zlog_debug( + "%pSG register forward skipped as group is SSM", + &sg); return 0; } @@ -327,23 +228,22 @@ static int pim_mroute_msg_wholepkt(int fd, struct interface *ifp, return 0; } - pim_register_send((uint8_t *)buf + sizeof(struct ip), - ntohs(ip_hdr->ip_len) - sizeof(struct ip), + pim_register_send((uint8_t *)buf + sizeof(ipv_hdr), + ntohs(IPV_LEN(ip_hdr)) - sizeof(ipv_hdr), pim_ifp->primary_address, rpg, 0, up); } return 0; } -static int pim_mroute_msg_wrongvif(int fd, struct interface *ifp, - const struct igmpmsg *msg) +int pim_mroute_msg_wrongvif(int fd, struct interface *ifp, const kernmsg *msg) { struct pim_ifchannel *ch; struct pim_interface *pim_ifp; pim_sgaddr sg; memset(&sg, 0, sizeof(sg)); - sg.src = msg->im_src; - sg.grp = msg->im_dst; + sg.src = msg->msg_im_src; + sg.grp = msg->msg_im_dst; /* Send Assert(S,G) on iif as response to WRONGVIF kernel upcall. @@ -358,16 +258,18 @@ static int pim_mroute_msg_wrongvif(int fd, struct interface *ifp, if (!ifp) { if (PIM_DEBUG_MROUTE) - zlog_debug("%s: WRONGVIF (S,G)=%pSG could not find input interface for input_vif_index=%d", - __func__, &sg, msg->im_vif); + zlog_debug( + "%s: WRONGVIF (S,G)=%pSG could not find input interface for input_vif_index=%d", + __func__, &sg, msg->msg_im_vif); return -1; } pim_ifp = ifp->info; if (!pim_ifp) { if (PIM_DEBUG_MROUTE) - zlog_debug("%s: WRONGVIF (S,G)=%pSG multicast not enabled on interface %s", - __func__, &sg, ifp->name); + zlog_debug( + "%s: WRONGVIF (S,G)=%pSG multicast not enabled on interface %s", + __func__, &sg, ifp->name); return -2; } @@ -375,16 +277,17 @@ static int pim_mroute_msg_wrongvif(int fd, struct interface *ifp, if (!ch) { pim_sgaddr star_g = sg; if (PIM_DEBUG_MROUTE) - zlog_debug("%s: WRONGVIF (S,G)=%pSG could not find channel on interface %s", - __func__, &sg, ifp->name); + zlog_debug( + "%s: WRONGVIF (S,G)=%pSG could not find channel on interface %s", + __func__, &sg, ifp->name); star_g.src = PIMADDR_ANY; ch = pim_ifchannel_find(ifp, &star_g); if (!ch) { if (PIM_DEBUG_MROUTE) - zlog_debug("%s: WRONGVIF (*,G)=%pSG could not find channel on interface %s", - __func__, &star_g, - ifp->name); + zlog_debug( + "%s: WRONGVIF (*,G)=%pSG could not find channel on interface %s", + __func__, &star_g, ifp->name); return -3; } } @@ -433,10 +336,9 @@ static int pim_mroute_msg_wrongvif(int fd, struct interface *ifp, return 0; } -static int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp, - const char *buf) +int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp, const char *buf) { - const struct ip *ip_hdr = (const struct ip *)buf; + const ipv_hdr *ip_hdr = (const ipv_hdr *)buf; struct pim_interface *pim_ifp; struct pim_instance *pim; struct pim_ifchannel *ch; @@ -447,8 +349,8 @@ static int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp, pim_ifp = ifp->info; memset(&sg, 0, sizeof(sg)); - sg.src = ip_hdr->ip_src; - sg.grp = ip_hdr->ip_dst; + sg.src = IPV_SRC(ip_hdr); + sg.grp = IPV_DST(ip_hdr); ch = pim_ifchannel_find(ifp, &sg); if (ch) { @@ -481,8 +383,8 @@ static int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp, struct pim_rpf *rpf = RP(pim_ifp->pim, sg.grp); /* No RPF or No RPF interface or No mcast on RPF interface */ - if (!rpf || !rpf->source_nexthop.interface - || !rpf->source_nexthop.interface->info) + if (!rpf || !rpf->source_nexthop.interface || + !rpf->source_nexthop.interface->info) return 0; /* @@ -512,7 +414,7 @@ static int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp, * bow out of doing a nexthop lookup and * setting the SPTBIT to true */ - if (up->upstream_register.s_addr != INADDR_ANY && + if (!(pim_addr_is_any(up->upstream_register)) && pim_nexthop_lookup(pim_ifp->pim, &source, up->upstream_register, 0)) { pim_register_stop_send(source.interface, &sg, @@ -551,8 +453,9 @@ static int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp, NULL); if (!up) { if (PIM_DEBUG_MROUTE) - zlog_debug("%pSG: WRONGVIF%s unable to create upstream on interface", - &sg, ifp->name); + zlog_debug( + "%pSG: WRONGVIF%s unable to create upstream on interface", + &sg, ifp->name); return -2; } PIM_UPSTREAM_FLAG_SET_SRC_STREAM(up->flags); @@ -577,119 +480,6 @@ static int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp, return 0; } -static int pim_mroute_msg(struct pim_instance *pim, const char *buf, - int buf_size, ifindex_t ifindex) -{ - struct interface *ifp; - const struct ip *ip_hdr; - const struct igmpmsg *msg; - - if (buf_size < (int)sizeof(struct ip)) - return 0; - - ip_hdr = (const struct ip *)buf; - - if (ip_hdr->ip_p == IPPROTO_IGMP) { -#if PIM_IPV == 4 - struct pim_interface *pim_ifp; - struct in_addr ifaddr; - struct gm_sock *igmp; - const struct prefix *connected_src; - - /* We have the IP packet but we do not know which interface this - * packet was - * received on. Find the interface that is on the same subnet as - * the source - * of the IP packet. - */ - ifp = if_lookup_by_index(ifindex, pim->vrf->vrf_id); - - if (!ifp || !ifp->info) - return 0; - - connected_src = pim_if_connected_to_source(ifp, ip_hdr->ip_src); - - if (!connected_src && !pim_addr_is_any(ip_hdr->ip_src)) { - if (PIM_DEBUG_IGMP_PACKETS) { - zlog_debug("Recv IGMP packet on interface: %s from a non-connected source: %pI4", - ifp->name, &ip_hdr->ip_src); - } - return 0; - } - - pim_ifp = ifp->info; - ifaddr = connected_src ? connected_src->u.prefix4 - : pim_ifp->primary_address; - igmp = pim_igmp_sock_lookup_ifaddr(pim_ifp->gm_socket_list, - ifaddr); - - if (PIM_DEBUG_IGMP_PACKETS) { - zlog_debug( - "%s(%s): igmp kernel upcall on %s(%p) for %pI4 -> %pI4", - __func__, pim->vrf->name, ifp->name, igmp, - &ip_hdr->ip_src, &ip_hdr->ip_dst); - } - if (igmp) - pim_igmp_packet(igmp, (char *)buf, buf_size); - else if (PIM_DEBUG_IGMP_PACKETS) { - zlog_debug( - "No IGMP socket on interface: %s with connected source: %pI4", - ifp->name, &ifaddr); - } -#endif - } else if (ip_hdr->ip_p) { - if (PIM_DEBUG_MROUTE_DETAIL) { - zlog_debug( - "%s: no kernel upcall proto=%d src: %pI4 dst: %pI4 msg_size=%d", - __func__, ip_hdr->ip_p, &ip_hdr->ip_src, &ip_hdr->ip_dst, - buf_size); - } - - } else { - msg = (const struct igmpmsg *)buf; - - ifp = pim_if_find_by_vif_index(pim, msg->im_vif); - - if (!ifp) - return 0; - if (PIM_DEBUG_MROUTE) { - zlog_debug( - "%s: pim kernel upcall %s type=%d ip_p=%d from fd=%d for (S,G)=(%pI4,%pI4) on %s vifi=%d size=%d", - __func__, igmpmsgtype2str[msg->im_msgtype], - msg->im_msgtype, ip_hdr->ip_p, - pim->mroute_socket, &msg->im_src, &msg->im_dst, ifp->name, - msg->im_vif, buf_size); - } - - switch (msg->im_msgtype) { - case IGMPMSG_WRONGVIF: - return pim_mroute_msg_wrongvif(pim->mroute_socket, ifp, - msg); - case IGMPMSG_NOCACHE: - return pim_mroute_msg_nocache(pim->mroute_socket, ifp, - msg); - case IGMPMSG_WHOLEPKT: - return pim_mroute_msg_wholepkt(pim->mroute_socket, ifp, - (const char *)msg); - case IGMPMSG_WRVIFWHOLE: - return pim_mroute_msg_wrvifwhole( - pim->mroute_socket, ifp, (const char *)msg); - default: - break; - } - } - - return 0; -} -#else /* PIM_IPV != 4 */ - -static int pim_mroute_msg(struct pim_instance *pim, const char *buf, - int buf_size, ifindex_t ifindex) -{ - return 0; -} -#endif /* PIM_IPV != 4 */ - static void mroute_read(struct thread *t) { struct pim_instance *pim; @@ -726,6 +516,8 @@ static void mroute_read(struct thread *t) /* Keep reading */ done: mroute_read_on(pim); + + return; } static void mroute_read_on(struct pim_instance *pim) @@ -745,8 +537,11 @@ int pim_mroute_socket_enable(struct pim_instance *pim) frr_with_privs(&pimd_privs) { +#if PIM_IPV == 4 fd = socket(AF_INET, SOCK_RAW, IPPROTO_IGMP); - +#else + fd = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6); +#endif if (fd < 0) { zlog_warn("Could not create mroute socket: errno=%d: %s", errno, @@ -814,7 +609,7 @@ int pim_mroute_add_vif(struct interface *ifp, pim_addr ifaddr, unsigned char flags) { struct pim_interface *pim_ifp = ifp->info; - struct vifctl vc; + pim_vifctl vc; int err; if (PIM_DEBUG_MROUTE) @@ -823,9 +618,10 @@ int pim_mroute_add_vif(struct interface *ifp, pim_addr ifaddr, pim_ifp->pim->vrf->name); memset(&vc, 0, sizeof(vc)); - vc.vifc_vifi = pim_ifp->mroute_vif_index; + vc.vc_vifi = pim_ifp->mroute_vif_index; +#if PIM_IPV == 4 #ifdef VIFF_USE_IFINDEX - vc.vifc_lcl_ifindex = ifp->ifindex; + vc.vc_lcl_ifindex = ifp->ifindex; #else if (ifaddr.s_addr == INADDR_ANY) { zlog_warn( @@ -833,24 +629,29 @@ int pim_mroute_add_vif(struct interface *ifp, pim_addr ifaddr, __func__); return -1; } - memcpy(&vc.vifc_lcl_addr, &ifaddr, sizeof(vc.vifc_lcl_addr)); + memcpy(&vc.vc_lcl_addr, &ifaddr, sizeof(vc.vc_lcl_addr)); +#endif +#else + vc.vc_pifi = ifp->ifindex; #endif - vc.vifc_flags = flags; - vc.vifc_threshold = PIM_MROUTE_MIN_TTL; - vc.vifc_rate_limit = 0; + vc.vc_flags = flags; + vc.vc_threshold = PIM_MROUTE_MIN_TTL; + vc.vc_rate_limit = 0; +#if PIM_IPV == 4 #ifdef PIM_DVMRP_TUNNEL - if (vc.vifc_flags & VIFF_TUNNEL) { - memcpy(&vc.vifc_rmt_addr, &vif_remote_addr, - sizeof(vc.vifc_rmt_addr)); + if (vc.vc_flags & VIFF_TUNNEL) { + memcpy(&vc.vc_rmt_addr, &vif_remote_addr, + sizeof(vc.vc_rmt_addr)); } #endif +#endif - err = setsockopt(pim_ifp->pim->mroute_socket, IPPROTO_IP, MRT_ADD_VIF, + err = setsockopt(pim_ifp->pim->mroute_socket, PIM_IPPROTO, MRT_ADD_VIF, (void *)&vc, sizeof(vc)); if (err) { zlog_warn( - "%s: failure: setsockopt(fd=%d,IPPROTO_IP,MRT_ADD_VIF,vif_index=%d,ifaddr=%pPAs,flag=%d): errno=%d: %s", + "%s: failure: setsockopt(fd=%d,PIM_IPPROTO,MRT_ADD_VIF,vif_index=%d,ifaddr=%pPAs,flag=%d): errno=%d: %s", __func__, pim_ifp->pim->mroute_socket, ifp->ifindex, &ifaddr, flags, errno, safe_strerror(errno)); return -2; @@ -862,7 +663,7 @@ int pim_mroute_add_vif(struct interface *ifp, pim_addr ifaddr, int pim_mroute_del_vif(struct interface *ifp) { struct pim_interface *pim_ifp = ifp->info; - struct vifctl vc; + pim_vifctl vc; int err; if (PIM_DEBUG_MROUTE) @@ -871,13 +672,13 @@ int pim_mroute_del_vif(struct interface *ifp) pim_ifp->pim->vrf->name); memset(&vc, 0, sizeof(vc)); - vc.vifc_vifi = pim_ifp->mroute_vif_index; + vc.vc_vifi = pim_ifp->mroute_vif_index; - err = setsockopt(pim_ifp->pim->mroute_socket, IPPROTO_IP, MRT_DEL_VIF, + err = setsockopt(pim_ifp->pim->mroute_socket, PIM_IPPROTO, MRT_DEL_VIF, (void *)&vc, sizeof(vc)); if (err) { zlog_warn( - "%s %s: failure: setsockopt(fd=%d,IPPROTO_IP,MRT_DEL_VIF,vif_index=%d): errno=%d: %s", + "%s %s: failure: setsockopt(fd=%d,PIM_IPPROTO,MRT_DEL_VIF,vif_index=%d): errno=%d: %s", __FILE__, __func__, pim_ifp->pim->mroute_socket, pim_ifp->mroute_vif_index, errno, safe_strerror(errno)); return -2; @@ -985,20 +786,21 @@ static int pim_mroute_add(struct channel_oil *c_oil, const char *name) && *oil_parent(c_oil) != 0) { *oil_parent(tmp_oil) = 0; } - err = setsockopt(pim->mroute_socket, IPPROTO_IP, MRT_ADD_MFC, + /* For IPv6 MRT_ADD_MFC is defined to MRT6_ADD_MFC */ + err = setsockopt(pim->mroute_socket, PIM_IPPROTO, MRT_ADD_MFC, &tmp_oil->oil, sizeof(tmp_oil->oil)); if (!err && !c_oil->installed && !pim_addr_is_any(*oil_origin(c_oil)) && *oil_parent(c_oil) != 0) { *oil_parent(tmp_oil) = *oil_parent(c_oil); - err = setsockopt(pim->mroute_socket, IPPROTO_IP, MRT_ADD_MFC, + err = setsockopt(pim->mroute_socket, PIM_IPPROTO, MRT_ADD_MFC, &tmp_oil->oil, sizeof(tmp_oil->oil)); } if (err) { zlog_warn( - "%s %s: failure: setsockopt(fd=%d,IPPROTO_IP,MRT_ADD_MFC): errno=%d: %s", + "%s %s: failure: setsockopt(fd=%d,PIM_IPPROTO,MRT_ADD_MFC): errno=%d: %s", __FILE__, __func__, pim->mroute_socket, errno, safe_strerror(errno)); return -2; @@ -1174,12 +976,12 @@ int pim_mroute_del(struct channel_oil *c_oil, const char *name) return -2; } - err = setsockopt(pim->mroute_socket, IPPROTO_IP, MRT_DEL_MFC, + err = setsockopt(pim->mroute_socket, PIM_IPPROTO, MRT_DEL_MFC, &c_oil->oil, sizeof(c_oil->oil)); if (err) { if (PIM_DEBUG_MROUTE) zlog_warn( - "%s %s: failure: setsockopt(fd=%d,IPPROTO_IP,MRT_DEL_MFC): errno=%d: %s", + "%s %s: failure: setsockopt(fd=%d,PIM_IPPROTO,MRT_DEL_MFC): errno=%d: %s", __FILE__, __func__, pim->mroute_socket, errno, safe_strerror(errno)); return -2; @@ -1201,6 +1003,7 @@ int pim_mroute_del(struct channel_oil *c_oil, const char *name) void pim_mroute_update_counters(struct channel_oil *c_oil) { struct pim_instance *pim = c_oil->pim; + pim_sioc_sg_req sgreq; c_oil->cc.oldpktcnt = c_oil->cc.pktcnt; c_oil->cc.oldbytecnt = c_oil->cc.bytecnt; @@ -1219,29 +1022,33 @@ void pim_mroute_update_counters(struct channel_oil *c_oil) return; } -#if PIM_IPV == 4 - struct sioc_sg_req sgreq; memset(&sgreq, 0, sizeof(sgreq)); + +#if PIM_IPV == 4 sgreq.src = *oil_origin(c_oil); sgreq.grp = *oil_mcastgrp(c_oil); - pim_zlookup_sg_statistics(c_oil); - if (ioctl(pim->mroute_socket, SIOCGETSGCNT, &sgreq)) { +#else + sgreq.src = c_oil->oil.mf6cc_origin; + sgreq.grp = c_oil->oil.mf6cc_mcastgrp; + /* TODO Zlookup_sg_statistics for V6 to be added */ +#endif + if (ioctl(pim->mroute_socket, PIM_SIOCGETSGCNT, &sgreq)) { pim_sgaddr sg; sg.src = *oil_origin(c_oil); sg.grp = *oil_mcastgrp(c_oil); - zlog_warn("ioctl(SIOCGETSGCNT=%lu) failure for (S,G)=%pSG: errno=%d: %s", - (unsigned long)SIOCGETSGCNT, &sg, - errno, safe_strerror(errno)); + zlog_warn( + "ioctl(PIM_SIOCGETSGCNT=%lu) failure for (S,G)=%pSG: errno=%d: %s", + (unsigned long)PIM_SIOCGETSGCNT, &sg, errno, + safe_strerror(errno)); return; } c_oil->cc.pktcnt = sgreq.pktcnt; c_oil->cc.bytecnt = sgreq.bytecnt; c_oil->cc.wrong_if = sgreq.wrong_if; -#endif return; } diff --git a/pimd/pim_mroute.h b/pimd/pim_mroute.h index 14b0a8ccaf..35ba60bf35 100644 --- a/pimd/pim_mroute.h +++ b/pimd/pim_mroute.h @@ -30,153 +30,107 @@ #define __EXTENSIONS__ #endif -#include <netinet/in.h> -#ifdef HAVE_NETINET_IP_MROUTE_H -#include <netinet/ip_mroute.h> -#endif #define PIM_MROUTE_MIN_TTL (1) #if PIM_IPV == 4 + +#include <netinet/in.h> #if defined(HAVE_LINUX_MROUTE_H) #include <linux/mroute.h> #else -/* - Below: from <linux/mroute.h> -*/ - -#ifndef MAXVIFS -#define MAXVIFS (256) +#ifndef VTYSH_EXTRACT_PL +#include "linux/mroute.h" #endif - -#ifndef SIOCGETVIFCNT -#define SIOCGETVIFCNT SIOCPROTOPRIVATE /* IP protocol privates */ -#define SIOCGETSGCNT (SIOCPROTOPRIVATE+1) -#define SIOCGETRPF (SIOCPROTOPRIVATE+2) #endif -#ifndef MRT_INIT -#define MRT_BASE 200 -#define MRT_INIT (MRT_BASE) /* Activate the kernel mroute code */ -#define MRT_DONE (MRT_BASE+1) /* Shutdown the kernel mroute */ -#define MRT_ADD_VIF (MRT_BASE+2) /* Add a virtual interface */ -#define MRT_DEL_VIF (MRT_BASE+3) /* Delete a virtual interface */ -#define MRT_ADD_MFC (MRT_BASE+4) /* Add a multicast forwarding entry */ -#define MRT_DEL_MFC (MRT_BASE+5) /* Delete a multicast forwarding entry */ -#define MRT_VERSION (MRT_BASE+6) /* Get the kernel multicast version */ -#define MRT_ASSERT (MRT_BASE+7) /* Activate PIM assert mode */ -#define MRT_PIM (MRT_BASE+8) /* enable PIM code */ -#endif +typedef struct vifctl pim_vifctl; +typedef struct igmpmsg kernmsg; +typedef struct sioc_sg_req pim_sioc_sg_req; -#ifndef MRT_TABLE -#define MRT_TABLE (209) /* Specify mroute table ID */ -#endif +#define vc_vifi vifc_vifi +#define vc_flags vifc_flags +#define vc_threshold vifc_threshold +#define vc_rate_limit vifc_rate_limit +#define vc_lcl_addr vifc_lcl_addr +#define vc_lcl_ifindex vifc_lcl_ifindex +#define vc_rmt_addr vifc_rmt_addr -#ifndef HAVE_VIFI_T -typedef unsigned short vifi_t; -#endif +#define msg_im_vif im_vif +#define msg_im_src im_src +#define msg_im_dst im_dst -#ifndef HAVE_STRUCT_VIFCTL -struct vifctl { - vifi_t vifc_vifi; /* Index of VIF */ - unsigned char vifc_flags; /* VIFF_ flags */ - unsigned char vifc_threshold; /* ttl limit */ - unsigned int vifc_rate_limit; /* Rate limiter values (NI) */ - struct in_addr vifc_lcl_addr; /* Our address */ - struct in_addr vifc_rmt_addr; /* IPIP tunnel addr */ -}; +#ifndef IGMPMSG_WRVIFWHOLE +#define IGMPMSG_WRVIFWHOLE 4 /* For PIM processing */ #endif -#ifndef HAVE_STRUCT_MFCCTL -struct mfcctl { - struct in_addr mfcc_origin; /* Origin of mcast */ - struct in_addr mfcc_mcastgrp; /* Group in question */ - vifi_t mfcc_parent; /* Where it arrived */ - unsigned char mfcc_ttls[MAXVIFS]; /* Where it is going */ - unsigned int mfcc_pkt_cnt; /* pkt count for src-grp */ - unsigned int mfcc_byte_cnt; - unsigned int mfcc_wrong_if; - int mfcc_expire; -}; +#ifndef PIM_IPPROTO +#define PIM_IPPROTO IPPROTO_IP +#endif +#ifndef PIM_SIOCGETSGCNT +#define PIM_SIOCGETSGCNT SIOCGETSGCNT #endif -/* - * Group count retrieval for mrouted - */ -/* - struct sioc_sg_req sgreq; - memset(&sgreq, 0, sizeof(sgreq)); - memcpy(&sgreq.src, &source_addr, sizeof(sgreq.src)); - memcpy(&sgreq.grp, &group_addr, sizeof(sgreq.grp)); - ioctl(mrouter_s4, SIOCGETSGCNT, &sgreq); - */ -#ifndef HAVE_STRUCT_SIOC_SG_REQ -struct sioc_sg_req { - struct in_addr src; - struct in_addr grp; - unsigned long pktcnt; - unsigned long bytecnt; - unsigned long wrong_if; -}; +#else /* PIM_IPV != 4 */ + +#include <netinet/ip6.h> + +#if defined(HAVE_LINUX_MROUTE6_H) +#include <linux/mroute6.h> +#else +#ifndef VTYSH_EXTRACT_PL +#include "linux/mroute6.h" +#endif #endif -/* - * To get vif packet counts - */ -/* - struct sioc_vif_req vreq; - memset(&vreq, 0, sizeof(vreq)); - vreq.vifi = vif_index; - ioctl(mrouter_s4, SIOCGETVIFCNT, &vreq); - */ -#ifndef HAVE_STRUCT_SIOC_VIF_REQ -struct sioc_vif_req { - vifi_t vifi; /* Which iface */ - unsigned long icount; /* In packets */ - unsigned long ocount; /* Out packets */ - unsigned long ibytes; /* In bytes */ - unsigned long obytes; /* Out bytes */ -}; +#ifndef MRT_INIT +#define MRT_BASE MRT6_BASE +#define MRT_INIT MRT6_INIT +#define MRT_DONE MRT6_DONE +#define MRT_ADD_VIF MRT6_ADD_MIF +#define MRT_DEL_VIF MRT6_DEL_MIF +#define MRT_ADD_MFC MRT6_ADD_MFC +#define MRT_DEL_MFC MRT6_DEL_MFC +#define MRT_VERSION MRT6_VERSION +#define MRT_ASSERT MRT6_ASSERT +#define MRT_PIM MRT6_PIM #endif -/* - * Pseudo messages used by mrouted - */ -#ifndef IGMPMSG_NOCACHE -#define IGMPMSG_NOCACHE 1 /* Kern cache fill request to mrouted */ -#define IGMPMSG_WRONGVIF 2 /* For PIM assert processing (unused) */ -#define IGMPMSG_WHOLEPKT 3 /* For PIM Register processing */ +#ifndef PIM_IPPROTO +#define PIM_IPPROTO IPPROTO_IPV6 #endif -#ifndef HAVE_STRUCT_IGMPMSG -struct igmpmsg { - uint32_t unused1, unused2; - unsigned char im_msgtype; /* What is this */ - unsigned char im_mbz; /* Must be zero */ - unsigned char im_vif; /* Interface (this ought to be a vifi_t!) */ - unsigned char unused3; - struct in_addr im_src, im_dst; -}; +#ifndef PIM_SIOCGETSGCNT +#define PIM_SIOCGETSGCNT SIOCGETSGCNT_IN6 #endif -#endif /* HAVE_LINUX_MROUTE_H */ +#ifndef MRT6MSG_WRMIFWHOLE +#define MRT6MSG_WRMIFWHOLE 4 /* For PIM processing */ +#endif -typedef struct mfcctl pim_mfcctl; +typedef struct mif6ctl pim_vifctl; +typedef struct mrt6msg kernmsg; +typedef mifi_t vifi_t; +typedef struct sioc_sg_req6 pim_sioc_sg_req; -#else /* PIM_IPV != 4 */ -#if defined(HAVE_LINUX_MROUTE6_H) -#include <linux/mroute6.h> -#endif +#define vc_vifi mif6c_mifi +#define vc_flags mif6c_flags +#define vc_threshold vifc_threshold +#define vc_pifi mif6c_pifi +#define vc_rate_limit vifc_rate_limit -typedef struct mf6cctl pim_mfcctl; +#define msg_im_vif im6_mif +#define msg_im_src im6_src +#define msg_im_dst im6_dst +#ifndef MAXVIFS #define MAXVIFS IF_SETSIZE #endif -#ifndef IGMPMSG_WRVIFWHOLE -#define IGMPMSG_WRVIFWHOLE 4 /* For PIM processing */ +#define VIFF_REGISTER MIFF_REGISTER #endif + /* Above: from <linux/mroute.h> */ @@ -201,4 +155,11 @@ int pim_mroute_del(struct channel_oil *c_oil, const char *name); void pim_mroute_update_counters(struct channel_oil *c_oil); bool pim_mroute_allow_iif_in_oil(struct channel_oil *c_oil, int oif_index); +int pim_mroute_msg(struct pim_instance *pim, const char *buf, size_t buf_size, + ifindex_t ifindex); +int pim_mroute_msg_nocache(int fd, struct interface *ifp, const kernmsg *msg); +int pim_mroute_msg_wholepkt(int fd, struct interface *ifp, const char *buf); +int pim_mroute_msg_wrongvif(int fd, struct interface *ifp, const kernmsg *msg); +int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp, const char *buf); +int pim_mroute_set(struct pim_instance *pim, int enable); #endif /* PIM_MROUTE_H */ diff --git a/pimd/pim_mroute_msg.c b/pimd/pim_mroute_msg.c new file mode 100644 index 0000000000..7d80488c68 --- /dev/null +++ b/pimd/pim_mroute_msg.c @@ -0,0 +1,239 @@ +/* + * PIM for Quagga + * Copyright (C) 2022 Dell Technologies Ltd + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * 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. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; see the file COPYING; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <zebra.h> +#include "log.h" +#include "privs.h" +#include "if.h" +#include "prefix.h" +#include "vty.h" +#include "plist.h" +#include "sockopt.h" +#include "lib_errors.h" +#include "lib/network.h" + +#include "pimd.h" +#include "pim_mroute.h" +#include "pim_oil.h" +#include "pim_str.h" +#include "pim_iface.h" +#include "pim_macro.h" +#include "pim_rp.h" +#include "pim_oil.h" +#include "pim_msg.h" +#include "pim_sock.h" + + +int pim_mroute_set(struct pim_instance *pim, int enable) +{ + int err; + int opt, data; + socklen_t data_len = sizeof(data); + + /* + * We need to create the VRF table for the pim mroute_socket + */ + if (pim->vrf->vrf_id != VRF_DEFAULT) { + frr_with_privs(&pimd_privs) { + + data = pim->vrf->data.l.table_id; + err = setsockopt(pim->mroute_socket, PIM_IPPROTO, + MRT_TABLE, &data, data_len); + if (err) { + zlog_warn( + "%s %s: failure: setsockopt(fd=%d,PIM_IPPROTO, MRT_TABLE=%d): errno=%d: %s", + __FILE__, __func__, pim->mroute_socket, + data, errno, safe_strerror(errno)); + return -1; + } + + } + } + + frr_with_privs(&pimd_privs) { + opt = enable ? MRT_INIT : MRT_DONE; + /* + * *BSD *cares* about what value we pass down + * here + */ + data = 1; + err = setsockopt(pim->mroute_socket, PIM_IPPROTO, opt, &data, + data_len); + if (err) { + zlog_warn( + "%s %s: failure: setsockopt(fd=%d,PIM_IPPROTO,%s=%d): errno=%d: %s", + __FILE__, __func__, pim->mroute_socket, + enable ? "MRT_INIT" : "MRT_DONE", data, errno, + safe_strerror(errno)); + return -1; + } + } + +#if defined(HAVE_IP_PKTINFO) + if (enable) { + /* Linux and Solaris IP_PKTINFO */ + data = 1; + if (setsockopt(pim->mroute_socket, PIM_IPPROTO, IP_PKTINFO, + &data, data_len)) { + zlog_warn( + "Could not set IP_PKTINFO on socket fd=%d: errno=%d: %s", + pim->mroute_socket, errno, + safe_strerror(errno)); + } + } +#endif + + setsockopt_so_recvbuf(pim->mroute_socket, 1024 * 1024 * 8); + + if (set_nonblocking (pim->mroute_socket) < 0) { + zlog_warn( + "Could not set non blocking on socket fd=%d: errno=%d: %s", + pim->mroute_socket, errno, + safe_strerror(errno)); + } + + if (enable) { +#if defined linux + int upcalls = IGMPMSG_WRVIFWHOLE; + opt = MRT_PIM; + + err = setsockopt(pim->mroute_socket, PIM_IPPROTO, opt, &upcalls, + sizeof(upcalls)); + if (err) { + zlog_warn( + "Failure to register for VIFWHOLE and WRONGVIF upcalls %d %s", + errno, safe_strerror(errno)); + return -1; + } +#else + zlog_warn( + "PIM-SM will not work properly on this platform, until the ability to receive the WRVIFWHOLE upcall"); +#endif + + } + + return 0; +} + +static const char *const igmpmsgtype2str[IGMPMSG_WRVIFWHOLE + 1] = { + "<unknown_upcall?>", "NOCACHE", "WRONGVIF", "WHOLEPKT", "WRVIFWHOLE"}; + + +int pim_mroute_msg(struct pim_instance *pim, const char *buf, + size_t buf_size, ifindex_t ifindex) +{ + struct interface *ifp; + const struct ip *ip_hdr; + const struct igmpmsg *msg; + + if (buf_size < (int)sizeof(struct ip)) + return 0; + + ip_hdr = (const struct ip *)buf; + + if (ip_hdr->ip_p == IPPROTO_IGMP) { + struct pim_interface *pim_ifp; + struct in_addr ifaddr; + struct gm_sock *igmp; + const struct prefix *connected_src; + + /* We have the IP packet but we do not know which interface this + * packet was + * received on. Find the interface that is on the same subnet as + * the source + * of the IP packet. + */ + ifp = if_lookup_by_index(ifindex, pim->vrf->vrf_id); + + if (!ifp || !ifp->info) + return 0; + + connected_src = pim_if_connected_to_source(ifp, ip_hdr->ip_src); + + if (!connected_src) { + if (PIM_DEBUG_IGMP_PACKETS) { + zlog_debug( + "Recv IGMP packet on interface: %s from a non-connected source: %pI4", + ifp->name, &ip_hdr->ip_src); + } + return 0; + } + + pim_ifp = ifp->info; + ifaddr = connected_src->u.prefix4; + igmp = pim_igmp_sock_lookup_ifaddr(pim_ifp->gm_socket_list, + ifaddr); + + if (PIM_DEBUG_IGMP_PACKETS) { + zlog_debug( + "%s(%s): igmp kernel upcall on %s(%p) for %pI4 -> %pI4", + __func__, pim->vrf->name, ifp->name, igmp, + &ip_hdr->ip_src, &ip_hdr->ip_dst); + } + if (igmp) + pim_igmp_packet(igmp, (char *)buf, buf_size); + else if (PIM_DEBUG_IGMP_PACKETS) { + zlog_debug( + "No IGMP socket on interface: %s with connected source: %pFX", + ifp->name, connected_src); + } + } else if (ip_hdr->ip_p) { + if (PIM_DEBUG_MROUTE_DETAIL) { + zlog_debug( + "%s: no kernel upcall proto=%d src: %pI4 dst: %pI4 msg_size=%ld", + __func__, ip_hdr->ip_p, &ip_hdr->ip_src, + &ip_hdr->ip_dst, (long int)buf_size); + } + + } else { + msg = (const struct igmpmsg *)buf; + + ifp = pim_if_find_by_vif_index(pim, msg->im_vif); + + if (!ifp) + return 0; + if (PIM_DEBUG_MROUTE) { + zlog_debug( + "%s: pim kernel upcall %s type=%d ip_p=%d from fd=%d for (S,G)=(%pI4,%pI4) on %s vifi=%d size=%ld", + __func__, igmpmsgtype2str[msg->im_msgtype], + msg->im_msgtype, ip_hdr->ip_p, + pim->mroute_socket, &msg->im_src, &msg->im_dst, + ifp->name, msg->im_vif, (long int)buf_size); + } + + switch (msg->im_msgtype) { + case IGMPMSG_WRONGVIF: + return pim_mroute_msg_wrongvif(pim->mroute_socket, ifp, + msg); + case IGMPMSG_NOCACHE: + return pim_mroute_msg_nocache(pim->mroute_socket, ifp, + msg); + case IGMPMSG_WHOLEPKT: + return pim_mroute_msg_wholepkt(pim->mroute_socket, ifp, + (const char *)msg); + case IGMPMSG_WRVIFWHOLE: + return pim_mroute_msg_wrvifwhole( + pim->mroute_socket, ifp, (const char *)msg); + default: + break; + } + } + + return 0; +} diff --git a/pimd/pim_msg.c b/pimd/pim_msg.c index a0653e1a57..1eda51417f 100644 --- a/pimd/pim_msg.c +++ b/pimd/pim_msg.c @@ -38,10 +38,36 @@ #include "pim_jp_agg.h" #include "pim_oil.h" -void pim_msg_build_header(uint8_t *pim_msg, size_t pim_msg_size, - uint8_t pim_msg_type, bool no_fwd) +void pim_msg_build_header(pim_addr src, pim_addr dst, uint8_t *pim_msg, + size_t pim_msg_size, uint8_t pim_msg_type, + bool no_fwd) { struct pim_msg_header *header = (struct pim_msg_header *)pim_msg; + struct iovec iov[2], *iovp = iov; + + /* + * The checksum for Registers is done only on the first 8 bytes of the + * packet, including the PIM header and the next 4 bytes, excluding the + * data packet portion + * + * for IPv6, the pseudoheader upper-level protocol length is also + * truncated, so let's just set it here before everything else. + */ + if (pim_msg_type == PIM_MSG_TYPE_REGISTER) + pim_msg_size = PIM_MSG_REGISTER_LEN; + +#if PIM_IPV == 6 + struct ipv6_ph phdr = { + .src = src, + .dst = dst, + .ulpl = htonl(pim_msg_size), + .next_hdr = IPPROTO_PIM, + }; + + iovp->iov_base = &phdr; + iovp->iov_len = sizeof(phdr); + iovp++; +#endif /* * Write header @@ -51,18 +77,12 @@ void pim_msg_build_header(uint8_t *pim_msg, size_t pim_msg_size, header->Nbit = no_fwd; header->reserved = 0; - header->checksum = 0; - /* - * The checksum for Registers is done only on the first 8 bytes of the - * packet, - * including the PIM header and the next 4 bytes, excluding the data - * packet portion - */ - if (pim_msg_type == PIM_MSG_TYPE_REGISTER) - header->checksum = in_cksum(pim_msg, PIM_MSG_REGISTER_LEN); - else - header->checksum = in_cksum(pim_msg, pim_msg_size); + iovp->iov_base = header; + iovp->iov_len = pim_msg_size; + iovp++; + + header->checksum = in_cksumv(iov, iovp - iov); } uint8_t *pim_msg_addr_encode_ipv4_ucast(uint8_t *buf, struct in_addr addr) diff --git a/pimd/pim_msg.h b/pimd/pim_msg.h index 456c356d9f..733210af3a 100644 --- a/pimd/pim_msg.h +++ b/pimd/pim_msg.h @@ -161,10 +161,18 @@ struct pim_encoded_source_ipv6 { typedef struct pim_encoded_ipv4_unicast pim_encoded_unicast; typedef struct pim_encoded_group_ipv4 pim_encoded_group; typedef struct pim_encoded_source_ipv4 pim_encoded_source; +typedef struct ip ipv_hdr; +#define IPV_SRC(ip_hdr) ((ip_hdr))->ip_src +#define IPV_DST(ip_hdr) ((ip_hdr))->ip_dst +#define IPV_LEN(ip_hdr) ((ip_hdr))->ip_len #else typedef struct pim_encoded_ipv6_unicast pim_encoded_unicast; typedef struct pim_encoded_group_ipv6 pim_encoded_group; typedef struct pim_encoded_source_ipv6 pim_encoded_source; +typedef struct ip6_hdr ipv_hdr; +#define IPV_SRC(ip_hdr) ((ip_hdr))->ip6_src +#define IPV_DST(ip_hdr) ((ip_hdr))->ip6_dst +#define IPV_LEN(ip_hdr) ((ip_hdr))->ip6_plen #endif /* clang-format on */ @@ -208,8 +216,9 @@ static inline pim_sgaddr pim_sgaddr_from_iphdr(const void *iphdr) } #endif -void pim_msg_build_header(uint8_t *pim_msg, size_t pim_msg_size, - uint8_t pim_msg_type, bool no_fwd); +void pim_msg_build_header(pim_addr src, pim_addr dst, uint8_t *pim_msg, + size_t pim_msg_size, uint8_t pim_msg_type, + bool no_fwd); uint8_t *pim_msg_addr_encode_ipv4_ucast(uint8_t *buf, struct in_addr addr); uint8_t *pim_msg_addr_encode_ipv4_group(uint8_t *buf, struct in_addr addr); diff --git a/pimd/pim_nb_config.c b/pimd/pim_nb_config.c index 2fabee5dfd..7fe7c0395f 100644 --- a/pimd/pim_nb_config.c +++ b/pimd/pim_nb_config.c @@ -348,6 +348,7 @@ static bool is_pim_interface(const struct lyd_node *dnode) return false; } +#if PIM_IPV == 4 static int pim_cmd_igmp_start(struct interface *ifp) { struct pim_interface *pim_ifp; @@ -376,12 +377,14 @@ static int pim_cmd_igmp_start(struct interface *ifp) return NB_OK; } +#endif /* PIM_IPV == 4 */ /* * CLI reconfiguration affects the interface level (struct pim_interface). * This function propagates the reconfiguration to every active socket * for that interface. */ +#if PIM_IPV == 4 static void igmp_sock_query_interval_reconfig(struct gm_sock *igmp) { struct interface *ifp; @@ -406,6 +409,7 @@ static void igmp_sock_query_interval_reconfig(struct gm_sock *igmp) */ igmp_startup_mode_on(igmp); } +#endif static void igmp_sock_query_reschedule(struct gm_sock *igmp) { @@ -436,6 +440,7 @@ static void igmp_sock_query_reschedule(struct gm_sock *igmp) } } +#if PIM_IPV == 4 static void change_query_interval(struct pim_interface *pim_ifp, int query_interval) { @@ -449,6 +454,7 @@ static void change_query_interval(struct pim_interface *pim_ifp, igmp_sock_query_reschedule(igmp); } } +#endif static void change_query_max_response_time(struct pim_interface *pim_ifp, int query_max_response_time_dsec) @@ -2550,6 +2556,7 @@ int lib_interface_gmp_address_family_destroy(struct nb_cb_destroy_args *args) int lib_interface_gmp_address_family_enable_modify( struct nb_cb_modify_args *args) { +#if PIM_IPV == 4 struct interface *ifp; bool igmp_enable; struct pim_interface *pim_ifp; @@ -2597,7 +2604,9 @@ int lib_interface_gmp_address_family_enable_modify( pim_if_delete(ifp); } } - +#else + /* TBD Depends on MLD data structure changes */ +#endif /* PIM_IPV == 4 */ return NB_OK; } @@ -2671,6 +2680,7 @@ int lib_interface_gmp_address_family_mld_version_modify( case NB_EV_PREPARE: case NB_EV_ABORT: case NB_EV_APPLY: + /* TBD depends on MLD data structure changes */ break; } @@ -2697,6 +2707,7 @@ int lib_interface_gmp_address_family_mld_version_destroy( int lib_interface_gmp_address_family_query_interval_modify( struct nb_cb_modify_args *args) { +#if PIM_IPV == 4 struct interface *ifp; int query_interval; @@ -2710,7 +2721,9 @@ int lib_interface_gmp_address_family_query_interval_modify( query_interval = yang_dnode_get_uint16(args->dnode, NULL); change_query_interval(ifp->info, query_interval); } - +#else + /* TBD Depends on MLD data structure changes */ +#endif return NB_OK; } @@ -2802,6 +2815,7 @@ int lib_interface_gmp_address_family_robustness_variable_modify( int lib_interface_gmp_address_family_static_group_create( struct nb_cb_create_args *args) { +#if PIM_IPV == 4 struct interface *ifp; struct ipaddr source_addr; struct ipaddr group_addr; @@ -2844,7 +2858,9 @@ int lib_interface_gmp_address_family_static_group_create( return NB_ERR_INCONSISTENCY; } } - +#else + /* TBD Depends on MLD data structure changes */ +#endif /* PIM_IPV == 4 */ return NB_OK; } diff --git a/pimd/pim_nht.c b/pimd/pim_nht.c index 3babddd877..94dcfb8265 100644 --- a/pimd/pim_nht.c +++ b/pimd/pim_nht.c @@ -55,7 +55,7 @@ void pim_sendmsg_zebra_rnh(struct pim_instance *pim, struct zclient *zclient, int ret; p = &(pnc->rpf.rpf_addr); - ret = zclient_send_rnh(zclient, command, p, false, false, + ret = zclient_send_rnh(zclient, command, p, SAFI_UNICAST, false, false, pim->vrf->vrf_id); if (ret == ZCLIENT_SEND_FAILURE) zlog_warn("sendmsg_nexthop: zclient_send_message() failed"); @@ -279,7 +279,7 @@ void pim_nht_bsr_del(struct pim_instance *pim, struct in_addr addr) } bool pim_nht_bsr_rpf_check(struct pim_instance *pim, struct in_addr bsr_addr, - struct interface *src_ifp, struct in_addr src_ip) + struct interface *src_ifp, pim_addr src_ip) { struct pim_nexthop_cache *pnc = NULL; struct pim_nexthop_cache lookup; diff --git a/pimd/pim_nht.h b/pimd/pim_nht.h index 568c2eb232..d51f622ece 100644 --- a/pimd/pim_nht.h +++ b/pimd/pim_nht.h @@ -76,6 +76,6 @@ void pim_nht_bsr_add(struct pim_instance *pim, struct in_addr bsr_addr); void pim_nht_bsr_del(struct pim_instance *pim, struct in_addr bsr_addr); /* RPF(bsr_addr) == src_ip%src_ifp? */ bool pim_nht_bsr_rpf_check(struct pim_instance *pim, struct in_addr bsr_addr, - struct interface *src_ifp, struct in_addr src_ip); + struct interface *src_ifp, pim_addr src_ip); #endif diff --git a/pimd/pim_oil.c b/pimd/pim_oil.c index d5e459b44e..5b5cc2c103 100644 --- a/pimd/pim_oil.c +++ b/pimd/pim_oil.c @@ -544,20 +544,27 @@ int pim_channel_add_oif(struct channel_oil *channel_oil, struct interface *oif, int pim_channel_oil_empty(struct channel_oil *c_oil) { +#if PIM_IPV == 4 + static struct mfcctl null_oil; +#else + static struct mf6cctl null_oil; +#endif + if (!c_oil) return 1; + /* exclude pimreg from the OIL when checking if the inherited_oil is * non-NULL. * pimreg device (in all vrfs) uses a vifi of * 0 (PIM_OIF_PIM_REGISTER_VIF) so we simply mfcc_ttls[0] */ + if (oil_if_has(c_oil, 0)) { #if PIM_IPV == 4 - static pim_mfcctl null_oil; - - return !memcmp(&c_oil->oil.mfcc_ttls[1], &null_oil.mfcc_ttls[1], - sizeof(null_oil.mfcc_ttls) - sizeof(null_oil.mfcc_ttls[0])); + null_oil.mfcc_ttls[0] = 1; #else - CPP_NOTICE("FIXME STUB"); - return false; + IF_SET(0, &null_oil.mf6cc_ifset); #endif + } + + return !oil_if_cmp(&c_oil->oil, &null_oil); } diff --git a/pimd/pim_oil.h b/pimd/pim_oil.h index a52e23351e..68b5ef474e 100644 --- a/pimd/pim_oil.h +++ b/pimd/pim_oil.h @@ -98,7 +98,11 @@ struct channel_oil { struct rb_pim_oil_item oil_rb; - pim_mfcctl oil; +#if PIM_IPV == 4 + struct mfcctl oil; +#else + struct mf6cctl oil; +#endif int installed; int oil_inherited_rescan; int oil_size; @@ -135,6 +139,12 @@ static inline void oil_if_set(struct channel_oil *c_oil, vifi_t ifi, uint8_t set { c_oil->oil.mfcc_ttls[ifi] = set; } + +static inline int oil_if_cmp(struct mfcctl *oil1, struct mfcctl *oil2) +{ + return memcmp(&oil1->mfcc_ttls[0], &oil2->mfcc_ttls[0], + sizeof(oil1->mfcc_ttls)); +} #else static inline pim_addr *oil_origin(struct channel_oil *c_oil) { @@ -163,6 +173,12 @@ static inline void oil_if_set(struct channel_oil *c_oil, mifi_t ifi, bool set) else IF_CLR(ifi, &c_oil->oil.mf6cc_ifset); } + +static inline int oil_if_cmp(struct mf6cctl *oil1, struct mf6cctl *oil2) +{ + return memcmp(&oil1->mf6cc_ifset, &oil2->mf6cc_ifset, + sizeof(oil1->mf6cc_ifset)); +} #endif extern int pim_channel_oil_compare(const struct channel_oil *c1, diff --git a/pimd/pim_pim.c b/pimd/pim_pim.c index 535448f013..50bbc0fe18 100644 --- a/pimd/pim_pim.c +++ b/pimd/pim_pim.c @@ -138,31 +138,34 @@ void pim_sock_delete(struct interface *ifp, const char *delete_message) } /* For now check dst address for hello, assrt and join/prune is all pim rtr */ -static bool pim_pkt_dst_addr_ok(enum pim_msg_type type, in_addr_t addr) +static bool pim_pkt_dst_addr_ok(enum pim_msg_type type, pim_addr addr) { if ((type == PIM_MSG_TYPE_HELLO) || (type == PIM_MSG_TYPE_ASSERT) || (type == PIM_MSG_TYPE_JOIN_PRUNE)) { - if (addr != qpim_all_pim_routers_addr.s_addr) + if (pim_addr_cmp(addr, qpim_all_pim_routers_addr)) return false; } return true; } -int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len) +int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len, + pim_sgaddr sg) { - struct ip *ip_hdr; + struct iovec iov[2], *iovp = iov; +#if PIM_IPV == 4 + struct ip *ip_hdr = (struct ip *)buf; size_t ip_hlen; /* ip header length in bytes */ - char src_str[INET_ADDRSTRLEN]; - char dst_str[INET_ADDRSTRLEN]; +#endif uint8_t *pim_msg; - int pim_msg_len; + uint32_t pim_msg_len = 0; uint16_t pim_checksum; /* received checksum */ uint16_t checksum; /* computed checksum */ struct pim_neighbor *neigh; struct pim_msg_header *header; bool no_fwd; +#if PIM_IPV == 4 if (len < sizeof(*ip_hdr)) { if (PIM_DEBUG_PIM_PACKETS) zlog_debug( @@ -171,11 +174,31 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len) return -1; } - ip_hdr = (struct ip *)buf; ip_hlen = ip_hdr->ip_hl << 2; /* ip_hl gives length in 4-byte words */ + sg = pim_sgaddr_from_iphdr(ip_hdr); pim_msg = buf + ip_hlen; pim_msg_len = len - ip_hlen; +#else + struct ipv6_ph phdr = { + .src = sg.src, + .dst = sg.grp, + .ulpl = htonl(len), + .next_hdr = IPPROTO_PIM, + }; + + iovp->iov_base = &phdr; + iovp->iov_len = sizeof(phdr); + iovp++; + + /* NB: header is not included in IPv6 RX */ + pim_msg = buf; + pim_msg_len = len; +#endif + + iovp->iov_base = pim_msg; + iovp->iov_len = pim_msg_len; + iovp++; header = (struct pim_msg_header *)pim_msg; if (pim_msg_len < PIM_PIM_MIN_LEN) { @@ -208,10 +231,21 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len) pim_msg_len, PIM_MSG_REGISTER_LEN); return -1; } + +#if PIM_IPV == 6 + phdr.ulpl = htonl(PIM_MSG_REGISTER_LEN); +#endif /* First 8 byte header checksum */ - checksum = in_cksum(pim_msg, PIM_MSG_REGISTER_LEN); + iovp[-1].iov_len = PIM_MSG_REGISTER_LEN; + checksum = in_cksumv(iov, iovp - iov); + if (checksum != pim_checksum) { - checksum = in_cksum(pim_msg, pim_msg_len); +#if PIM_IPV == 6 + phdr.ulpl = htonl(pim_msg_len); +#endif + iovp[-1].iov_len = pim_msg_len; + + checksum = in_cksumv(iov, iovp - iov); if (checksum != pim_checksum) { if (PIM_DEBUG_PIM_PACKETS) zlog_debug( @@ -223,7 +257,7 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len) } } } else { - checksum = in_cksum(pim_msg, pim_msg_len); + checksum = in_cksumv(iov, iovp - iov); if (checksum != pim_checksum) { if (PIM_DEBUG_PIM_PACKETS) zlog_debug( @@ -235,43 +269,29 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len) } if (PIM_DEBUG_PIM_PACKETS) { - pim_inet4_dump("<src?>", ip_hdr->ip_src, src_str, - sizeof(src_str)); - pim_inet4_dump("<dst?>", ip_hdr->ip_dst, dst_str, - sizeof(dst_str)); zlog_debug( - "Recv PIM %s packet from %s to %s on %s: ttl=%d pim_version=%d pim_msg_size=%d checksum=%x", - pim_pim_msgtype2str(header->type), src_str, dst_str, - ifp->name, ip_hdr->ip_ttl, header->ver, pim_msg_len, - checksum); - if (PIM_DEBUG_PIM_PACKETDUMP_RECV) { + "Recv PIM %s packet from %pPA to %pPA on %s: pim_version=%d pim_msg_size=%d checksum=%x", + pim_pim_msgtype2str(header->type), &sg.src, &sg.grp, + ifp->name, header->ver, pim_msg_len, checksum); + if (PIM_DEBUG_PIM_PACKETDUMP_RECV) pim_pkt_dump(__func__, pim_msg, pim_msg_len); - } } - if (!pim_pkt_dst_addr_ok(header->type, ip_hdr->ip_dst.s_addr)) { - char dst_str[INET_ADDRSTRLEN]; - char src_str[INET_ADDRSTRLEN]; - - pim_inet4_dump("<dst?>", ip_hdr->ip_dst, dst_str, - sizeof(dst_str)); - pim_inet4_dump("<src?>", ip_hdr->ip_src, src_str, - sizeof(src_str)); + if (!pim_pkt_dst_addr_ok(header->type, sg.grp)) { zlog_warn( - "%s: Ignoring Pkt. Unexpected IP destination %s for %s (Expected: all_pim_routers_addr) from %s", - __func__, dst_str, pim_pim_msgtype2str(header->type), - src_str); + "%s: Ignoring Pkt. Unexpected IP destination %pPA for %s (Expected: all_pim_routers_addr) from %pPA", + __func__, &sg.grp, pim_pim_msgtype2str(header->type), + &sg.src); return -1; } switch (header->type) { case PIM_MSG_TYPE_HELLO: - return pim_hello_recv(ifp, ip_hdr->ip_src, - pim_msg + PIM_MSG_HEADER_LEN, + return pim_hello_recv(ifp, sg.src, pim_msg + PIM_MSG_HEADER_LEN, pim_msg_len - PIM_MSG_HEADER_LEN); break; case PIM_MSG_TYPE_REGISTER: - return pim_register_recv(ifp, ip_hdr->ip_dst, ip_hdr->ip_src, + return pim_register_recv(ifp, sg.grp, sg.src, pim_msg + PIM_MSG_HEADER_LEN, pim_msg_len - PIM_MSG_HEADER_LEN); break; @@ -280,38 +300,37 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len) pim_msg_len - PIM_MSG_HEADER_LEN); break; case PIM_MSG_TYPE_JOIN_PRUNE: - neigh = pim_neighbor_find(ifp, ip_hdr->ip_src); + neigh = pim_neighbor_find(ifp, sg.src); if (!neigh) { if (PIM_DEBUG_PIM_PACKETS) zlog_debug( - "%s %s: non-hello PIM message type=%d from non-neighbor %s on %s", + "%s %s: non-hello PIM message type=%d from non-neighbor %pPA on %s", __FILE__, __func__, header->type, - src_str, ifp->name); + &sg.src, ifp->name); return -1; } pim_neighbor_timer_reset(neigh, neigh->holdtime); - return pim_joinprune_recv(ifp, neigh, ip_hdr->ip_src, + return pim_joinprune_recv(ifp, neigh, sg.src, pim_msg + PIM_MSG_HEADER_LEN, pim_msg_len - PIM_MSG_HEADER_LEN); break; case PIM_MSG_TYPE_ASSERT: - neigh = pim_neighbor_find(ifp, ip_hdr->ip_src); + neigh = pim_neighbor_find(ifp, sg.src); if (!neigh) { if (PIM_DEBUG_PIM_PACKETS) zlog_debug( - "%s %s: non-hello PIM message type=%d from non-neighbor %s on %s", + "%s %s: non-hello PIM message type=%d from non-neighbor %pPA on %s", __FILE__, __func__, header->type, - src_str, ifp->name); + &sg.src, ifp->name); return -1; } pim_neighbor_timer_reset(neigh, neigh->holdtime); - return pim_assert_recv(ifp, neigh, ip_hdr->ip_src, + return pim_assert_recv(ifp, neigh, sg.src, pim_msg + PIM_MSG_HEADER_LEN, pim_msg_len - PIM_MSG_HEADER_LEN); break; case PIM_MSG_TYPE_BOOTSTRAP: - return pim_bsm_process(ifp, ip_hdr, pim_msg, pim_msg_len, - no_fwd); + return pim_bsm_process(ifp, &sg, pim_msg, pim_msg_len, no_fwd); break; default: @@ -348,6 +367,8 @@ static void pim_sock_read(struct thread *t) pim_ifp = ifp->info; while (cont) { + pim_sgaddr sg; + len = pim_socket_recvfromto(fd, buf, sizeof(buf), &from, &fromlen, &to, &tolen, &ifindex); if (len < 0) { @@ -377,7 +398,15 @@ static void pim_sock_read(struct thread *t) ifindex); goto done; } - int fail = pim_pim_packet(ifp, buf, len); +#if PIM_IPV == 4 + sg.src = ((struct sockaddr_in *)&from)->sin_addr; + sg.grp = ((struct sockaddr_in *)&to)->sin_addr; +#else + sg.src = ((struct sockaddr_in6 *)&from)->sin6_addr; + sg.grp = ((struct sockaddr_in6 *)&to)->sin6_addr; +#endif + + int fail = pim_pim_packet(ifp, buf, len, sg); if (fail) { if (PIM_DEBUG_PIM_PACKETS) zlog_debug("%s: pim_pim_packet() return=%d", @@ -520,75 +549,62 @@ void pim_sock_reset(struct interface *ifp) pim_ifstat_reset(ifp); } +#if PIM_IPV == 4 static uint16_t ip_id = 0; - +#endif static int pim_msg_send_frame(int fd, char *buf, size_t len, struct sockaddr *dst, size_t salen, const char *ifname) { - struct ip *ip = (struct ip *)buf; - - if (sendto(fd, buf, len, MSG_DONTWAIT, dst, salen) < 0) { - char dst_str[INET_ADDRSTRLEN]; - - switch (errno) { - case EMSGSIZE: { - size_t hdrsize = sizeof(struct ip); - size_t newlen1 = ((len - hdrsize) / 2) & 0xFFF8; - size_t sendlen = newlen1 + hdrsize; - size_t offset = ntohs(ip->ip_off); - - ip->ip_len = htons(sendlen); - ip->ip_off = htons(offset | IP_MF); - if (pim_msg_send_frame(fd, buf, sendlen, dst, salen, - ifname) == 0) { - struct ip *ip2 = (struct ip *)(buf + newlen1); - size_t newlen2 = len - sendlen; - sendlen = newlen2 + hdrsize; - - memcpy(ip2, ip, hdrsize); - ip2->ip_len = htons(sendlen); - ip2->ip_off = htons(offset + (newlen1 >> 3)); - return pim_msg_send_frame(fd, (char *)ip2, - sendlen, dst, salen, - ifname); - } - } + if (sendto(fd, buf, len, MSG_DONTWAIT, dst, salen) >= 0) + return 0; - return -1; - default: - if (PIM_DEBUG_PIM_PACKETS) { - pim_inet4_dump("<dst?>", ip->ip_dst, dst_str, - sizeof(dst_str)); - zlog_warn( - "%s: sendto() failure to %s: iface=%s fd=%d msg_size=%zd: errno=%d: %s", - __func__, dst_str, ifname, fd, len, - errno, safe_strerror(errno)); - } - return -1; - } +#if PIM_IPV == 4 + if (errno == EMSGSIZE) { + struct ip *ip = (struct ip *)buf; + size_t hdrsize = sizeof(struct ip); + size_t newlen1 = ((len - hdrsize) / 2) & 0xFFF8; + size_t sendlen = newlen1 + hdrsize; + size_t offset = ntohs(ip->ip_off); + int ret; + + ip->ip_len = htons(sendlen); + ip->ip_off = htons(offset | IP_MF); + + ret = pim_msg_send_frame(fd, buf, sendlen, dst, salen, ifname); + if (ret) + return ret; + + struct ip *ip2 = (struct ip *)(buf + newlen1); + size_t newlen2 = len - sendlen; + + sendlen = newlen2 + hdrsize; + + memcpy(ip2, ip, hdrsize); + ip2->ip_len = htons(sendlen); + ip2->ip_off = htons(offset + (newlen1 >> 3)); + return pim_msg_send_frame(fd, (char *)ip2, sendlen, dst, salen, + ifname); } +#endif - return 0; + zlog_warn( + "%s: sendto() failure to %pSU: iface=%s fd=%d msg_size=%zd: %m", + __func__, dst, ifname, fd, len); + return -1; } int pim_msg_send(int fd, pim_addr src, pim_addr dst, uint8_t *pim_msg, int pim_msg_size, const char *ifname) { - struct sockaddr_in to; socklen_t tolen; unsigned char buffer[10000]; unsigned char *msg_start; uint8_t ttl; struct pim_msg_header *header; - struct ip *ip; memset(buffer, 0, 10000); - int sendlen = sizeof(struct ip) + pim_msg_size; - - msg_start = buffer + sizeof(struct ip); - memcpy(msg_start, pim_msg, pim_msg_size); header = (struct pim_msg_header *)pim_msg; /* @@ -618,7 +634,11 @@ int pim_msg_send(int fd, pim_addr src, pim_addr dst, uint8_t *pim_msg, break; } - ip = (struct ip *)buffer; +#if PIM_IPV == 4 + struct ip *ip = (struct ip *)buffer; + struct sockaddr_in to = {}; + int sendlen = sizeof(*ip) + pim_msg_size; + ip->ip_id = htons(++ip_id); ip->ip_hl = 5; ip->ip_v = 4; @@ -629,17 +649,34 @@ int pim_msg_send(int fd, pim_addr src, pim_addr dst, uint8_t *pim_msg, ip->ip_ttl = ttl; ip->ip_len = htons(sendlen); - if (PIM_DEBUG_PIM_PACKETS) { - char dst_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<dst?>", dst, dst_str, sizeof(dst_str)); - zlog_debug("%s: to %s on %s: msg_size=%d checksum=%x", __func__, - dst_str, ifname, pim_msg_size, header->checksum); - } - - memset(&to, 0, sizeof(to)); to.sin_family = AF_INET; to.sin_addr = dst; tolen = sizeof(to); +#else + struct ip6_hdr *ip = (struct ip6_hdr *)buffer; + struct sockaddr_in6 to = {}; + int sendlen = sizeof(*ip) + pim_msg_size; + + ip->ip6_flow = 0; + ip->ip6_vfc = (6 << 4) | (IPTOS_PREC_INTERNETCONTROL >> 4); + ip->ip6_plen = htons(pim_msg_size); + ip->ip6_nxt = PIM_IP_PROTO_PIM; + ip->ip6_hlim = ttl; + ip->ip6_src = src; + ip->ip6_dst = dst; + + to.sin6_family = AF_INET6; + to.sin6_addr = dst; + tolen = sizeof(to); +#endif + + msg_start = buffer + sizeof(*ip); + memcpy(msg_start, pim_msg, pim_msg_size); + + if (PIM_DEBUG_PIM_PACKETS) + zlog_debug("%s: to %pPA on %s: msg_size=%d checksum=%x", + __func__, &dst, ifname, pim_msg_size, + header->checksum); if (PIM_DEBUG_PIM_PACKETDUMP_SEND) { pim_pkt_dump(__func__, pim_msg, pim_msg_size); @@ -659,20 +696,16 @@ static int hello_send(struct interface *ifp, uint16_t holdtime) pim_ifp = ifp->info; - if (PIM_DEBUG_PIM_HELLO) { - char dst_str[INET_ADDRSTRLEN]; - pim_inet4_dump("<dst?>", qpim_all_pim_routers_addr, dst_str, - sizeof(dst_str)); + if (PIM_DEBUG_PIM_HELLO) zlog_debug( - "%s: to %s on %s: holdt=%u prop_d=%u overr_i=%u dis_join_supp=%d dr_prio=%u gen_id=%08x addrs=%d", - __func__, dst_str, ifp->name, holdtime, - pim_ifp->pim_propagation_delay_msec, + "%s: to %pPA on %s: holdt=%u prop_d=%u overr_i=%u dis_join_supp=%d dr_prio=%u gen_id=%08x addrs=%d", + __func__, &qpim_all_pim_routers_addr, ifp->name, + holdtime, pim_ifp->pim_propagation_delay_msec, pim_ifp->pim_override_interval_msec, PIM_IF_TEST_PIM_CAN_DISABLE_JOIN_SUPPRESSION( pim_ifp->options), pim_ifp->pim_dr_priority, pim_ifp->pim_generation_id, listcount(ifp->connected)); - } pim_tlv_size = pim_hello_build_tlv( ifp, pim_msg + PIM_PIM_MIN_LEN, @@ -690,7 +723,9 @@ static int hello_send(struct interface *ifp, uint16_t holdtime) assert(pim_msg_size >= PIM_PIM_MIN_LEN); assert(pim_msg_size <= PIM_PIM_BUFSIZE_WRITE); - pim_msg_build_header(pim_msg, pim_msg_size, PIM_MSG_TYPE_HELLO, false); + pim_msg_build_header(pim_ifp->primary_address, + qpim_all_pim_routers_addr, pim_msg, pim_msg_size, + PIM_MSG_TYPE_HELLO, false); if (pim_msg_send(pim_ifp->pim_sock_fd, pim_ifp->primary_address, qpim_all_pim_routers_addr, pim_msg, pim_msg_size, diff --git a/pimd/pim_pim.h b/pimd/pim_pim.h index 1931e8cee8..822d8a18fa 100644 --- a/pimd/pim_pim.h +++ b/pimd/pim_pim.h @@ -54,7 +54,8 @@ void pim_sock_delete(struct interface *ifp, const char *delete_message); void pim_hello_restart_now(struct interface *ifp); void pim_hello_restart_triggered(struct interface *ifp); -int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len); +int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len, + pim_sgaddr sg); int pim_msg_send(int fd, pim_addr src, pim_addr dst, uint8_t *pim_msg, int pim_msg_size, const char *ifname); diff --git a/pimd/pim_register.c b/pimd/pim_register.c index 7fa36e5a44..45bcad3c26 100644 --- a/pimd/pim_register.c +++ b/pimd/pim_register.c @@ -88,7 +88,8 @@ void pim_register_stop_send(struct interface *ifp, pim_sgaddr *sg, length = pim_encode_addr_ucast(b1, sg->src); b1length += length; - pim_msg_build_header(buffer, b1length + PIM_MSG_REGISTER_STOP_LEN, + pim_msg_build_header(src, originator, buffer, + b1length + PIM_MSG_REGISTER_STOP_LEN, PIM_MSG_TYPE_REG_STOP, false); pinfo = (struct pim_interface *)ifp->info; @@ -261,7 +262,8 @@ void pim_register_send(const uint8_t *buf, int buf_size, struct in_addr src, memcpy(b1, (const unsigned char *)buf, buf_size); - pim_msg_build_header(buffer, buf_size + PIM_MSG_REGISTER_LEN, + pim_msg_build_header(src, rpg->rpf_addr.u.prefix4, buffer, + buf_size + PIM_MSG_REGISTER_LEN, PIM_MSG_TYPE_REGISTER, false); ++pinfo->pim_ifstat_reg_send; diff --git a/pimd/pim_register.h b/pimd/pim_register.h index 0ebef40c58..79c64d995f 100644 --- a/pimd/pim_register.h +++ b/pimd/pim_register.h @@ -35,11 +35,11 @@ int pim_register_stop_recv(struct interface *ifp, uint8_t *buf, int buf_size); int pim_register_recv(struct interface *ifp, pim_addr dest_addr, pim_addr src_addr, uint8_t *tlv_buf, int tlv_buf_size); -void pim_register_send(const uint8_t *buf, int buf_size, struct in_addr src, +void pim_register_send(const uint8_t *buf, int buf_size, pim_addr src, struct pim_rpf *rpg, int null_register, struct pim_upstream *up); -void pim_register_stop_send(struct interface *ifp, pim_sgaddr *sg, - struct in_addr src, struct in_addr originator); +void pim_register_stop_send(struct interface *ifp, pim_sgaddr *sg, pim_addr src, + pim_addr originator); void pim_register_join(struct pim_upstream *up); void pim_null_register_send(struct pim_upstream *up); void pim_reg_del_on_couldreg_fail(struct interface *ifp); diff --git a/pimd/pim_ssmpingd.c b/pimd/pim_ssmpingd.c index da903bd980..afa7e37da1 100644 --- a/pimd/pim_ssmpingd.c +++ b/pimd/pim_ssmpingd.c @@ -212,7 +212,7 @@ static void ssmpingd_delete(struct ssmpingd_sock *ss) if (close(ss->sock_fd)) { zlog_warn( - "%s: failure closing ssmpingd sock_fd=%d for source %pI4: errno=%d: %s", + "%s: failure closing ssmpingd sock_fd=%d for source %pPA: errno=%d: %s", __func__, ss->sock_fd, &ss->source_addr, errno, safe_strerror(errno)); /* warning only */ @@ -262,7 +262,7 @@ static int ssmpingd_read_msg(struct ssmpingd_sock *ss) if (len < 0) { zlog_warn( - "%s: failure receiving ssmping for source %pI4 on fd=%d: errno=%d: %s", + "%s: failure receiving ssmping for source %pPA on fd=%d: errno=%d: %s", __func__, &ss->source_addr, ss->sock_fd, errno, safe_strerror(errno)); return -1; @@ -272,7 +272,7 @@ static int ssmpingd_read_msg(struct ssmpingd_sock *ss) if (buf[0] != PIM_SSMPINGD_REQUEST) { zlog_warn( - "%s: bad ssmping type=%d from %pSUp to %pSUp on interface %s ifindex=%d fd=%d src=%pI4", + "%s: bad ssmping type=%d from %pSUp to %pSUp on interface %s ifindex=%d fd=%d src=%pPA", __func__, buf[0], &from, &to, ifp ? ifp->name : "<iface?>", ifindex, ss->sock_fd, &ss->source_addr); @@ -281,7 +281,7 @@ static int ssmpingd_read_msg(struct ssmpingd_sock *ss) if (PIM_DEBUG_SSMPINGD) { zlog_debug( - "%s: recv ssmping from %pSUp, to %pSUp, on interface %s ifindex=%d fd=%d src=%pI4", + "%s: recv ssmping from %pSUp, to %pSUp, on interface %s ifindex=%d fd=%d src=%pPA", __func__, &from, &to, ifp ? ifp->name : "<iface?>", ifindex, ss->sock_fd, &ss->source_addr); } @@ -330,7 +330,7 @@ static struct ssmpingd_sock *ssmpingd_new(struct pim_instance *pim, sock_fd = ssmpingd_socket(source_addr, /* port: */ 4321, /* mTTL: */ 64); if (sock_fd < 0) { - zlog_warn("%s: ssmpingd_socket() failure for source %pI4", + zlog_warn("%s: ssmpingd_socket() failure for source %pPA", __func__, &source_addr); return 0; } diff --git a/pimd/pim_vty.c b/pimd/pim_vty.c index a7d5986655..a0dea63b79 100644 --- a/pimd/pim_vty.c +++ b/pimd/pim_vty.c @@ -264,7 +264,7 @@ int pim_global_config_write_worker(struct pim_instance *pim, struct vty *vty) struct ssmpingd_sock *ss; ++writes; for (ALL_LIST_ELEMENTS_RO(pim->ssmpingd_list, node, ss)) { - vty_out(vty, "%sip ssmpingd %pI4\n", spaces, + vty_out(vty, "%sip ssmpingd %pPA\n", spaces, &ss->source_addr); ++writes; } diff --git a/pimd/subdir.am b/pimd/subdir.am index cda5acb004..ba7bdb3493 100644 --- a/pimd/subdir.am +++ b/pimd/subdir.am @@ -39,6 +39,7 @@ pim_common = \ pimd/pim_neighbor.c \ pimd/pim_nht.c \ pimd/pim_oil.c \ + pimd/pim_pim.c \ pimd/pim_routemap.c \ pimd/pim_rp.c \ pimd/pim_rpf.c \ @@ -72,11 +73,11 @@ pimd_pimd_SOURCES = \ pimd/pim_msdp.c \ pimd/pim_msdp_packet.c \ pimd/pim_msdp_socket.c \ - pimd/pim_pim.c \ pimd/pim_register.c \ pimd/pim_signals.c \ pimd/pim_zlookup.c \ pimd/pim_zpthread.c \ + pimd/pim_mroute_msg.c \ # end nodist_pimd_pimd_SOURCES = \ @@ -90,6 +91,7 @@ pimd_pim6d_SOURCES = \ pimd/pim6_main.c \ pimd/pim6_stubs.c \ pimd/pim6_cmd.c \ + pimd/pim6_mroute_msg.c \ # end nodist_pimd_pim6d_SOURCES = \ |
