15 boost::asio::io_context &io)
16 : agent_(agent), pkt_info_(info), io_(io) {}
28 Send(itf, vrf, cmd, 0, 0, mod);
32 uint32_t param1, uint32_t param2,
39 AgentHdr hdr(itf, vrf, cmd, param1, param2);
46 struct ether_header *eth = (
struct ether_header *)buff;
47 uint16_t encap_len =
sizeof(
struct ether_header);
53 if (len < encap_len) {
57 dest.
ToArray(eth->ether_dhost,
sizeof(eth->ether_dhost));
58 src.
ToArray(eth->ether_shost,
sizeof(eth->ether_shost));
60 uint16_t *ptr = (uint16_t *) (buff + ETHER_ADDR_LEN * 2);
62 *ptr = htons(ETHERTYPE_VLAN);
64 *ptr = htons(vlan_id & 0xFFF);
73 const uint16_t proto) {
80 const uint16_t proto) {
84 vlan_id =
static_cast<const VmInterface *
>(intrface)->tx_vlan_id();
87 return EthHdr(buff, len, src, dest, proto, vlan_id);
92 const uint16_t proto) {
94 return EthHdr(buff, len, intf, src, dest, proto);
99 vlan->
tpid = htons(0x8100);
100 vlan->
tci = htons(tci);
102 vlan->
tpid = htons(0x800);
107 in_addr_t src, in_addr_t dest, uint8_t protocol,
108 uint16_t
id, uint8_t ttl) {
109 struct ip *ip = (
struct ip *)buff;
110 if (buf_len <
sizeof(
struct ip))
116 ip->ip_len = htons(len);
117 ip->ip_id = htons(
id);
122 ip->ip_src.s_addr = src;
123 ip->ip_dst.s_addr = dest;
125 ip->ip_sum =
Csum((uint16_t *)ip, ip->ip_hl * 4, 0);
126 return sizeof(
struct ip);
130 uint8_t protocol, uint16_t
id, uint8_t ttl) {
133 src, dest, protocol,
id, ttl);
137 uint8_t hlim, uint8_t *src, uint8_t *dest) {
138 ip->ip6_flow = htonl(0x60000000);
139 ip->ip6_plen = htons(plen);
140 ip->ip6_nxt = next_header;
142 memcpy(ip->ip6_src.s6_addr, src, 16);
143 memcpy(ip->ip6_dst.s6_addr, dest, 16);
147 uint16_t src_port, uint16_t dest_port) {
148 udp->uh_sport = htons(src_port);
149 udp->uh_dport = htons(dest_port);
150 udp->uh_ulen = htons(len);
155 in_addr_t src, uint16_t src_port, in_addr_t dest,
156 uint16_t dest_port) {
157 if (buf_len <
sizeof(udphdr))
161 #ifdef VNSW_AGENT_UDP_CSUM
162 udp->uh_sum =
UdpCsum(src, dest, len, udp);
165 return sizeof(udphdr);
169 in_addr_t dest, uint16_t dest_port) {
175 uint8_t code, uint16_t word1, uint16_t word2) {
176 struct icmp *hdr = ((
struct icmp *)buff);
177 if (buf_len <
sizeof(hdr))
180 memset(hdr, 0,
sizeof(
struct icmp));
182 hdr->icmp_type =
type;
183 hdr->icmp_code = code;
184 if(type != ICMP_UNREACH) {
189 hdr->icmp_nextmtu = htons(word2);
191 if (type == ICMP_UNREACH)
197 struct icmp *hdr = ((
struct icmp *)buff);
198 hdr->icmp_cksum =
Csum((uint16_t *)buff, buf_len, 0);
202 struct igmp *hdr = ((
struct igmp *)buff);
203 hdr->igmp_cksum =
Csum((uint16_t *)buff, buf_len, 0);
207 uint16_t src_port,
const uint8_t *dest,
208 uint16_t dest_port, uint8_t next_hdr) {
215 const uint8_t *dest, uint16_t dest_port,
226 if (sum & 0x80000000)
227 sum = (sum & 0xFFFF) + (sum >> 16);
231 sum += *(uint8_t *)ptr;
237 sum =
Sum(ptr, len, sum);
240 sum = (sum & 0xFFFF) + (sum >> 16);
246 std::size_t len, udphdr *udp)
const {
250 return Csum((uint16_t *)udp, len, sum);
254 uint16_t plen, uint8_t next_hdr,
255 uint16_t *hdr)
const {
256 uint32_t len = htonl((uint32_t)plen);
257 uint32_t next = htonl((uint32_t)next_hdr);
260 pseudo =
Sum((uint16_t *)src, 16, 0);
261 pseudo =
Sum((uint16_t *)dest, 16, pseudo);
262 pseudo =
Sum((uint16_t *)&len, 4, pseudo);
263 pseudo =
Sum((uint16_t *)&next, 4, pseudo);
264 return Csum(hdr, plen, pseudo);
268 icmp6_hdr *icmp, uint16_t plen)
const {
269 return Ipv6Csum(src, dest, plen, IPPROTO_ICMPV6, (uint16_t *)icmp);
uint32_t EncapHeaderLen() const
bool ToArray(u_int8_t *p, size_t s) const
ProtoHandler(Agent *agent, boost::shared_ptr< PktInfo > info, boost::asio::io_context &io)
uint16_t UdpCsum(in_addr_t, in_addr_t, std::size_t, udphdr *) const
uint16_t Ipv6Csum(const uint8_t *src, const uint8_t *dest, uint16_t plen, uint8_t next_hdr, uint16_t *hdr) const
InterfaceTable * interface_table() const
uint16_t Csum(uint16_t *, std::size_t, uint32_t) const
boost::shared_ptr< PktInfo > pkt_info_
void IgmpChecksum(char *buff, uint16_t buf_len)
int EthHdr(const MacAddress &src, const MacAddress &dest, const uint16_t proto)
static const uint32_t kInvalidVlanId
void Send(uint32_t itf, uint32_t vrf, uint16_t, PktHandler::PktModuleName)
PktHandler * pkt_handler() const
void VlanHdr(uint8_t *ptr, uint16_t tci)
void Send(const AgentHdr &hdr, const PacketBufferPtr &buff)
void Ip6Hdr(ip6_hdr *ip, uint16_t plen, uint8_t next_header, uint8_t hlim, uint8_t *src, uint8_t *dest)
std::string AgentBackTrace(int skip=1)
void IcmpChecksum(char *buff, uint16_t buf_len)
#define ICMP_UNREACH_HDR_LEN
void UdpHdr(uint16_t len, in_addr_t src, uint16_t src_port, in_addr_t dest, uint16_t dest_port)
const Interface * FindInterface(size_t index) const
#define LOG(_Level, _Msg)
void FillUdpHdr(udphdr *udp, uint16_t len, uint16_t src_port, uint16_t dest_port)
uint32_t Sum(uint16_t *, std::size_t, uint32_t) const
uint32_t EncapHeaderLen() const
uint16_t IcmpHdr(char *buff, uint16_t buf_len, uint8_t type, uint8_t code, uint16_t word1, uint16_t word2)
uint16_t Icmpv6Csum(const uint8_t *src, const uint8_t *dest, icmp6_hdr *icmp, uint16_t plen) const
void IpHdr(uint16_t len, in_addr_t src, in_addr_t dest, uint8_t protocol, uint16_t id, uint8_t ttl)