MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ng_source_dup_mod

Function ng_source_dup_mod

freebsd/netgraph/ng_source.c:867–923  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

865}
866
867static int
868ng_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
921done:
922 return(error);
923}

Callers 1

ng_source_sendFunction · 0.85

Calls 5

m_dupFunction · 0.85
m_copypacketFunction · 0.85
ng_source_mod_counterFunction · 0.85
getmicrotimeFunction · 0.85
ng_source_packet_modFunction · 0.85

Tested by

no test coverage detected