Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __LINUX_PIM_H
0003 #define __LINUX_PIM_H
0004 
0005 #include <linux/skbuff.h>
0006 #include <asm/byteorder.h>
0007 
0008 /* Message types - V1 */
0009 #define PIM_V1_VERSION      cpu_to_be32(0x10000000)
0010 #define PIM_V1_REGISTER     1
0011 
0012 /* Message types - V2 */
0013 #define PIM_VERSION     2
0014 
0015 /* RFC7761, sec 4.9:
0016  *  Type
0017  *        Types for specific PIM messages.  PIM Types are:
0018  *
0019  *  Message Type                          Destination
0020  *  ---------------------------------------------------------------------
0021  *  0 = Hello                             Multicast to ALL-PIM-ROUTERS
0022  *  1 = Register                          Unicast to RP
0023  *  2 = Register-Stop                     Unicast to source of Register
0024  *                                        packet
0025  *  3 = Join/Prune                        Multicast to ALL-PIM-ROUTERS
0026  *  4 = Bootstrap                         Multicast to ALL-PIM-ROUTERS
0027  *  5 = Assert                            Multicast to ALL-PIM-ROUTERS
0028  *  6 = Graft (used in PIM-DM only)       Unicast to RPF'(S)
0029  *  7 = Graft-Ack (used in PIM-DM only)   Unicast to source of Graft
0030  *                                        packet
0031  *  8 = Candidate-RP-Advertisement        Unicast to Domain's BSR
0032  */
0033 enum {
0034     PIM_TYPE_HELLO,
0035     PIM_TYPE_REGISTER,
0036     PIM_TYPE_REGISTER_STOP,
0037     PIM_TYPE_JOIN_PRUNE,
0038     PIM_TYPE_BOOTSTRAP,
0039     PIM_TYPE_ASSERT,
0040     PIM_TYPE_GRAFT,
0041     PIM_TYPE_GRAFT_ACK,
0042     PIM_TYPE_CANDIDATE_RP_ADV
0043 };
0044 
0045 #define PIM_NULL_REGISTER   cpu_to_be32(0x40000000)
0046 
0047 /* RFC7761, sec 4.9:
0048  * The PIM header common to all PIM messages is:
0049  *   0                   1                   2                   3
0050  *   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
0051  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
0052  *  |PIM Ver| Type  |   Reserved    |           Checksum            |
0053  *  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
0054  */
0055 struct pimhdr {
0056     __u8    type;
0057     __u8    reserved;
0058     __be16  csum;
0059 };
0060 
0061 /* PIMv2 register message header layout (ietf-draft-idmr-pimvsm-v2-00.ps */
0062 struct pimreghdr {
0063     __u8    type;
0064     __u8    reserved;
0065     __be16  csum;
0066     __be32  flags;
0067 };
0068 
0069 int pim_rcv_v1(struct sk_buff *skb);
0070 
0071 static inline bool ipmr_pimsm_enabled(void)
0072 {
0073     return IS_BUILTIN(CONFIG_IP_PIMSM_V1) || IS_BUILTIN(CONFIG_IP_PIMSM_V2);
0074 }
0075 
0076 static inline struct pimhdr *pim_hdr(const struct sk_buff *skb)
0077 {
0078     return (struct pimhdr *)skb_transport_header(skb);
0079 }
0080 
0081 static inline u8 pim_hdr_version(const struct pimhdr *pimhdr)
0082 {
0083     return pimhdr->type >> 4;
0084 }
0085 
0086 static inline u8 pim_hdr_type(const struct pimhdr *pimhdr)
0087 {
0088     return pimhdr->type & 0xf;
0089 }
0090 
0091 /* check if the address is 224.0.0.13, RFC7761 sec 4.3.1 */
0092 static inline bool pim_ipv4_all_pim_routers(__be32 addr)
0093 {
0094     return addr == htonl(0xE000000D);
0095 }
0096 #endif