| 865 | } |
| 866 | |
| 867 | static int |
| 868 | ng_source_dup_mod(sc_p sc, struct mbuf *m0, struct mbuf **m_ptr) |
| 869 | { |
| 870 | struct mbuf *m; |
| 871 | struct ng_source_embed_cnt_info *cnt; |
| 872 | struct ng_source_embed_info *ts; |
| 873 | int modify; |
| 874 | int error = 0; |
| 875 | int i, increment; |
| 876 | |
| 877 | /* Are we going to modify packets? */ |
| 878 | modify = sc->embed_timestamp.flags & NGM_SOURCE_EMBED_ENABLE; |
| 879 | for (i = 0; !modify && i < NG_SOURCE_COUNTERS; ++i) |
| 880 | modify = sc->embed_counter[i].flags & NGM_SOURCE_EMBED_ENABLE; |
| 881 | |
| 882 | /* Duplicate the packet. */ |
| 883 | if (modify) |
| 884 | m = m_dup(m0, M_NOWAIT); |
| 885 | else |
| 886 | m = m_copypacket(m0, M_NOWAIT); |
| 887 | if (m == NULL) { |
| 888 | error = ENOBUFS; |
| 889 | goto done; |
| 890 | } |
| 891 | *m_ptr = m; |
| 892 | |
| 893 | if (!modify) |
| 894 | goto done; |
| 895 | |
| 896 | /* Modify the copied packet for sending. */ |
| 897 | KASSERT(M_WRITABLE(m), ("%s: packet not writable", __func__)); |
| 898 | |
| 899 | for (i = 0; i < NG_SOURCE_COUNTERS; ++i) { |
| 900 | cnt = &sc->embed_counter[i]; |
| 901 | if (cnt->flags & NGM_SOURCE_EMBED_ENABLE) { |
| 902 | if ((cnt->flags & NGM_SOURCE_INC_CNT_PER_LIST) == 0 || |
| 903 | sc->last_packet == m0) |
| 904 | increment = cnt->increment; |
| 905 | else |
| 906 | increment = 0; |
| 907 | ng_source_mod_counter(sc, cnt, m, increment); |
| 908 | } |
| 909 | } |
| 910 | |
| 911 | ts = &sc->embed_timestamp; |
| 912 | if (ts->flags & NGM_SOURCE_EMBED_ENABLE) { |
| 913 | struct timeval now; |
| 914 | getmicrotime(&now); |
| 915 | now.tv_sec = htonl(now.tv_sec); |
| 916 | now.tv_usec = htonl(now.tv_usec); |
| 917 | ng_source_packet_mod(sc, m, ts->offset, sizeof (now), |
| 918 | (caddr_t)&now, ts->flags); |
| 919 | } |
| 920 | |
| 921 | done: |
| 922 | return(error); |
| 923 | } |
no test coverage detected