Insert packet from into flow cache. */
| 645 | #ifdef INET |
| 646 | /* Insert packet from into flow cache. */ |
| 647 | int |
| 648 | ng_netflow_flow_add(priv_p priv, fib_export_p fe, struct ip *ip, |
| 649 | caddr_t upper_ptr, uint8_t upper_proto, uint8_t flags, |
| 650 | unsigned int src_if_index) |
| 651 | { |
| 652 | struct flow_entry *fle, *fle1; |
| 653 | struct flow_hash_entry *hsh; |
| 654 | struct flow_rec r; |
| 655 | int hlen, plen; |
| 656 | int error = 0; |
| 657 | uint16_t eproto; |
| 658 | uint8_t tcp_flags = 0; |
| 659 | |
| 660 | bzero(&r, sizeof(r)); |
| 661 | |
| 662 | if (ip->ip_v != IPVERSION) |
| 663 | return (EINVAL); |
| 664 | |
| 665 | hlen = ip->ip_hl << 2; |
| 666 | if (hlen < sizeof(struct ip)) |
| 667 | return (EINVAL); |
| 668 | |
| 669 | eproto = ETHERTYPE_IP; |
| 670 | /* Assume L4 template by default */ |
| 671 | r.flow_type = NETFLOW_V9_FLOW_V4_L4; |
| 672 | |
| 673 | r.r_src = ip->ip_src; |
| 674 | r.r_dst = ip->ip_dst; |
| 675 | r.fib = fe->fib; |
| 676 | |
| 677 | plen = ntohs(ip->ip_len); |
| 678 | |
| 679 | r.r_ip_p = ip->ip_p; |
| 680 | r.r_tos = ip->ip_tos; |
| 681 | |
| 682 | r.r_i_ifx = src_if_index; |
| 683 | |
| 684 | /* |
| 685 | * XXX NOTE: only first fragment of fragmented TCP, UDP and |
| 686 | * ICMP packet will be recorded with proper s_port and d_port. |
| 687 | * Following fragments will be recorded simply as IP packet with |
| 688 | * ip_proto = ip->ip_p and s_port, d_port set to zero. |
| 689 | * I know, it looks like bug. But I don't want to re-implement |
| 690 | * ip packet assebmling here. Anyway, (in)famous trafd works this way - |
| 691 | * and nobody complains yet :) |
| 692 | */ |
| 693 | if ((ip->ip_off & htons(IP_OFFMASK)) == 0) |
| 694 | switch(r.r_ip_p) { |
| 695 | case IPPROTO_TCP: |
| 696 | { |
| 697 | struct tcphdr *tcp; |
| 698 | |
| 699 | tcp = (struct tcphdr *)((caddr_t )ip + hlen); |
| 700 | r.r_sport = tcp->th_sport; |
| 701 | r.r_dport = tcp->th_dport; |
| 702 | tcp_flags = tcp->th_flags; |
| 703 | break; |
| 704 | } |
no test coverage detected