LCOV - code coverage report
Current view: top level - vnsw/agent/pkt - proto_handler.h (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 1 7 14.3 %
Date: 2026-11-09 02:10:49 Functions: 1 5 20.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
       3             :  * Copyright Contributors to the OpenSDN project
       4             :  */
       5             : 
       6             : #ifndef vnsw_agent_proto_handler_hpp
       7             : #define vnsw_agent_proto_handler_hpp
       8             : 
       9             : #include "pkt_handler.h"
      10             : 
      11             : // Pseudo header for UDP checksum
      12             : struct PseudoUdpHdr {
      13             :     in_addr_t src;
      14             :     in_addr_t dest;
      15             :     uint8_t   res;
      16             :     uint8_t   prot;
      17             :     uint16_t  len;
      18           0 :     PseudoUdpHdr(in_addr_t s, in_addr_t d, uint8_t p, uint16_t l) :
      19           0 :         src(s), dest(d), res(0), prot(p), len(l) { }
      20             : };
      21             : 
      22             : struct vlanhdr {
      23             :     uint16_t tpid;
      24             :     uint16_t tci;
      25             : };
      26             : 
      27             : // Protocol handler, to process an incoming packet
      28             : // Each protocol has a handler derived from this
      29             : class ProtoHandler {
      30             : public:
      31             :     ProtoHandler(Agent *agent, boost::shared_ptr<PktInfo> info,
      32             :                  boost::asio::io_context &io);
      33             :     virtual ~ProtoHandler();
      34             : 
      35             :     virtual bool Run() = 0;
      36             : 
      37             :     void Send(uint32_t itf, uint32_t vrf, uint16_t, PktHandler::PktModuleName);
      38             :     void Send(uint32_t itf, uint32_t vrf, uint16_t cmd,
      39             :               uint32_t param1, uint32_t param2, PktHandler::PktModuleName mod);
      40             : 
      41             :     int EthHdr(const MacAddress &src, const MacAddress &dest,
      42             :                const uint16_t proto);
      43             :     int EthHdr(char *buff, uint16_t len, const MacAddress &src,
      44             :                const MacAddress &dest, const uint16_t proto, uint16_t vlan_id);
      45             :     int EthHdr(char *buff, uint16_t len, const Interface *interface,
      46             :                const MacAddress &src, const MacAddress &dest,
      47             :                const uint16_t proto);
      48             :     int EthHdr(char *buff, uint16_t len, uint32_t ifindex,
      49             :                const MacAddress &src, const MacAddress &dest,
      50             :                const uint16_t proto);
      51             : 
      52             :     void VlanHdr(uint8_t *ptr, uint16_t tci);
      53             :     void IpHdr(uint16_t len, in_addr_t src, in_addr_t dest, uint8_t protocol,
      54             :                uint16_t id, uint8_t ttl);
      55             :     uint16_t IpHdr(char *buff, uint16_t buf_len, uint16_t len, in_addr_t src,
      56             :                    in_addr_t dest, uint8_t protocol, uint16_t id, uint8_t ttl);
      57             :     void Ip6Hdr(ip6_hdr *ip, uint16_t plen, uint8_t next_header,
      58             :                 uint8_t hlim, uint8_t *src, uint8_t *dest);
      59             :     void UdpHdr(uint16_t len, in_addr_t src, uint16_t src_port, in_addr_t dest,
      60             :                 uint16_t dest_port);
      61             :     void UdpHdr(udphdr *hdr, uint16_t len, const uint8_t *src, uint16_t src_port,
      62             :                 const uint8_t *dest, uint16_t dest_port, uint8_t next_hdr);
      63             :     void UdpHdr(uint16_t len, const uint8_t *src, uint16_t src_port,
      64             :                 const uint8_t *dest, uint16_t dest_port, uint8_t next_hdr);
      65             :     uint16_t UdpHdr(udphdr *udp, uint16_t buf_len, uint16_t len, in_addr_t src,
      66             :                     uint16_t src_port, in_addr_t dest, uint16_t dest_port);
      67             :     uint16_t IcmpHdr(char *buff, uint16_t buf_len, uint8_t type, uint8_t code,
      68             :                      uint16_t word1, uint16_t word2);
      69             :     void IcmpChecksum(char *buff, uint16_t buf_len);
      70             : 
      71             :     void IgmpChecksum(char *buff, uint16_t buf_len);
      72             : 
      73             :     uint32_t Sum(uint16_t *, std::size_t, uint32_t) const;
      74             :     uint16_t Csum(uint16_t *, std::size_t, uint32_t) const;
      75             :     uint16_t UdpCsum(in_addr_t, in_addr_t, std::size_t, udphdr *) const;
      76             :     uint16_t Ipv6Csum(const uint8_t *src, const uint8_t *dest,
      77             :                         uint16_t plen, uint8_t next_hdr, uint16_t *hdr) const;
      78             :     uint16_t Icmpv6Csum(const uint8_t *src, const uint8_t *dest,
      79             :                         icmp6_hdr *icmp, uint16_t plen) const;
      80             : 
      81        9339 :     Agent *agent() const { return agent_; }
      82           0 :     uint32_t GetVrfIndex() const { return pkt_info_->GetAgentHdr().vrf; }
      83           0 :     uint32_t GetInterfaceIndex() const {
      84           0 :         return pkt_info_->GetAgentHdr().ifindex;
      85             :     }
      86             :     uint16_t GetLength() const { return pkt_info_->len; }
      87             :     uint32_t GetCmdParam() const { return pkt_info_->GetAgentHdr().cmd_param; }
      88             : 
      89           0 :     PktInfo *pkt_info() const { return pkt_info_.get(); }
      90             :     uint32_t EncapHeaderLen() const;
      91             : protected:
      92             :     Agent   *agent_;
      93             :     boost::shared_ptr<PktInfo> pkt_info_;
      94             :     boost::asio::io_context &io_;
      95             : 
      96             : private:
      97             :     void FillUdpHdr(udphdr *udp, uint16_t len,
      98             :                     uint16_t src_port, uint16_t dest_port);
      99             : 
     100             :     DISALLOW_COPY_AND_ASSIGN(ProtoHandler);
     101             : };
     102             : 
     103             : #endif // vnsw_agent_proto_handler_hpp

Generated by: LCOV version 1.14