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

Function bw_meter_receive_packet

freebsd/netinet/ip_mroute.c:1918–2005  ·  view source on GitHub ↗

* Perform bandwidth measurement processing that may result in an upcall */

Source from the content-addressed store, hash-verified

1916 * Perform bandwidth measurement processing that may result in an upcall
1917 */
1918static void
1919bw_meter_receive_packet(struct bw_meter *x, int plen, struct timeval *nowp)
1920{
1921 struct timeval delta;
1922
1923 MFC_LOCK_ASSERT();
1924
1925 delta = *nowp;
1926 BW_TIMEVALDECR(&delta, &x->bm_start_time);
1927
1928 if (x->bm_flags & BW_METER_GEQ) {
1929 /*
1930 * Processing for ">=" type of bw_meter entry
1931 */
1932 if (BW_TIMEVALCMP(&delta, &x->bm_threshold.b_time, >)) {
1933 /* Reset the bw_meter entry */
1934 x->bm_start_time = *nowp;
1935 x->bm_measured.b_packets = 0;
1936 x->bm_measured.b_bytes = 0;
1937 x->bm_flags &= ~BW_METER_UPCALL_DELIVERED;
1938 }
1939
1940 /* Record that a packet is received */
1941 x->bm_measured.b_packets++;
1942 x->bm_measured.b_bytes += plen;
1943
1944 /*
1945 * Test if we should deliver an upcall
1946 */
1947 if (!(x->bm_flags & BW_METER_UPCALL_DELIVERED)) {
1948 if (((x->bm_flags & BW_METER_UNIT_PACKETS) &&
1949 (x->bm_measured.b_packets >= x->bm_threshold.b_packets)) ||
1950 ((x->bm_flags & BW_METER_UNIT_BYTES) &&
1951 (x->bm_measured.b_bytes >= x->bm_threshold.b_bytes))) {
1952 /* Prepare an upcall for delivery */
1953 bw_meter_prepare_upcall(x, nowp);
1954 x->bm_flags |= BW_METER_UPCALL_DELIVERED;
1955 }
1956 }
1957 } else if (x->bm_flags & BW_METER_LEQ) {
1958 /*
1959 * Processing for "<=" type of bw_meter entry
1960 */
1961 if (BW_TIMEVALCMP(&delta, &x->bm_threshold.b_time, >)) {
1962 /*
1963 * We are behind time with the multicast forwarding table
1964 * scanning for "<=" type of bw_meter entries, so test now
1965 * if we should deliver an upcall.
1966 */
1967 if (((x->bm_flags & BW_METER_UNIT_PACKETS) &&
1968 (x->bm_measured.b_packets <= x->bm_threshold.b_packets)) ||
1969 ((x->bm_flags & BW_METER_UNIT_BYTES) &&
1970 (x->bm_measured.b_bytes <= x->bm_threshold.b_bytes))) {
1971 /* Prepare an upcall for delivery */
1972 bw_meter_prepare_upcall(x, nowp);
1973 }
1974 /* Reschedule the bw_meter entry */
1975 unschedule_bw_meter(x);

Callers 1

ip_mdqFunction · 0.85

Calls 3

bw_meter_prepare_upcallFunction · 0.85
unschedule_bw_meterFunction · 0.85
schedule_bw_meterFunction · 0.85

Tested by

no test coverage detected