MOD_CC(9)
๐ MOD_CC ๐ โ the Kernel Developer's Manual, but make it make sense
okay bestie, sit down, hydrate, because we're about to talk about mod_cc, DECLARE_CC_MODULE and CCV โ aka Modular Congestion Control. this is from the Kernel Developer's Manual, and it's lowkey iconic. ๐ซถ
โจ NAME โจ
mod_cc, DECLARE_CC_MODULE, CCV โ Modular Congestion Control. that's the whole vibe. ๐
๐ธ SYNOPSIS ๐ธ
#include <netinet/tcp.h>
#include <netinet/cc/cc.h>
#include <netinet/cc/cc_module.h>
DECLARE_CC_MODULE(ccname, ccalgo);
CCV(ccv, what);
three headers, two macros, zero drama. periodt. โจ
๐ซ DESCRIPTION ๐ซ
so the mod_cc framework lets congestion control algorithms be implemented as dynamically loadable kernel modules via the kld(4) facility. literally plug-and-play for your congestion control. ๐ฆ
transport protocols can pick from the list of available algorithms on a connection-by-connection basis, or just vibe with the system default โ see mod_cc(4) for the deets.
mod_cc modules are identified by an ascii(7) name plus a set of hook functions, all wrapped up in a struct cc_algo, which has these members:
struct cc_algo {
char name[TCP_CA_NAME_MAX];
int (*mod_init) (void);
int (*mod_destroy) (void);
int (*cb_init) (struct cc_var *ccv);
void (*cb_destroy) (struct cc_var *ccv);
void (*conn_init) (struct cc_var *ccv);
void (*ack_received) (struct cc_var *ccv, uint16_t type);
void (*cong_signal) (struct cc_var *ccv, uint32_t type);
void (*post_recovery) (struct cc_var *ccv);
void (*after_idle) (struct cc_var *ccv);
int (*ctl_output)(struct cc_var *, struct sockopt *, void *);
};
okay now let's meet everybody one by one, bestie. ๐
nameโ the field that identifies the unique name of the algorithm. it should be no longer thanTCP_CA_NAME_MAX-1characters in length (theTCP_CA_NAME_MAXdefine lives in<netinet/tcp.h>for compatibility reasons, iykyk).mod_initโ called when a new module is loaded into the system, but before the registration process is complete. implement it if your module needs to set up some global state prior to being available for use by new connections. and listen: returning a non-zero value frommod_initwill cause the loading of the module to fail. no pressure. ๐ญmod_destroyโ called prior to unloading an existing module from the kernel. implement it if a module needs to clean up any global state before being removed from the kernel. the return value is currently ignored, so like, do what you want with it.cb_initโ called when a TCP control blockstruct tcpcbis created. implement it if a module needs to allocate memory for storing private per-connection state. returning a non-zero value fromcb_initwill cause the connection set up to be aborted, terminating the connection as a result. that's a big deal, bestie. โ ๏ธcb_destroyโ called when a TCP control blockstruct tcpcbis destroyed. implement it if a module needs to free memory allocated incb_init. the cleanup arc. ๐งนconn_initโ called when a new connection has been established and variables are being initialised. implement it to initialise congestion control algorithm variables for the newly established connection. fresh connection, fresh start, slay. โจack_receivedโ called when a TCP acknowledgement (ACK) packet is received. modules use thetypeargument as an input to their congestion management algorithms. the ACK types currently reported by the stack areCC_ACKandCC_DUPACK.CC_ACKindicates the received ACK acknowledges previously unacknowledged data.CC_DUPACKindicates the received ACK acknowledges data we have already received an ACK for.cong_signalโ called when a congestion event is detected by the TCP stack. modules use thetypeargument as an input to their congestion management algorithms. the congestion event types currently reported by the stack areCC_ECN,CC_RTO,CC_RTO_ERRandCC_NDUPACK. let's break it down:CC_ECNis reported when the TCP stack receives an explicit congestion notification (RFC3168).CC_RTOis reported when the retransmission time out timer fires.CC_RTO_ERRis reported if the retransmission time out timer fired in error.CC_NDUPACKis reported ifNduplicate ACKs have been received back-to-back, whereNis the fast retransmit duplicate ack threshold (N=3currently as perRFC5681).
post_recoveryโ called after the TCP connection has recovered from a congestion event. implement it to adjust state as required. healing era. ๐ฆafter_idleโ called when data transfer resumes after an idle period. implement it to adjust state as required.ctl_outputโ called whengetsockopt(2)orsetsockopt(2)is called on atcp(4)socket, with thestruct sockoptpointer forwarded unmodified from the TCP control, and avoid *pointer to algorithm specific argument.
the DECLARE_CC_MODULE() macro is a convenient little wrapper around the DECLARE_MODULE(9) macro, and it's what you use to register a mod_cc module with the mod_cc framework. the ccname argument specifies the module's name. the ccalgo argument points to the module's struct cc_algo. cute, right? ๐
mod_cc modules must instantiate a struct cc_algo, but are only required to set the name field, and optionally any of the function pointers. the stack will skip calling any function pointer which is NULL, so there is genuinely no requirement to implement any of the function pointers. using the C99 designated initialiser feature to set fields is encouraged. do it, bestie. ๐
each function pointer which deals with congestion control state gets passed a pointer to a struct cc_var, which has these members:
struct cc_var {
void *cc_data;
int bytes_this_ack;
tcp_seq curack;
uint32_t flags;
int type;
union ccv_container {
struct tcpcb *tcp;
struct sctp_nets *sctp;
} ccvc;
};
struct cc_var groups congestion control related variables into a single, embeddable structure and adds a layer of indirection to accessing transport protocol control blocks. the eventual goal? let a single set of mod_cc modules be shared between all congestion aware transport protocols. though currently only tcp(4) is supported. one day. ๐ญ
to aid the eventual transition towards this goal, direct use of variables from the transport protocol's data structures is strongly discouraged. however, it's inevitable at the current time to require access to some of these variables, so the CCV() macro exists as a convenience accessor. the ccv argument points to the struct cc_var passed into the function by the mod_cc framework. the what argument specifies the name of the variable to access. โจ
apart from the type and ccv_container fields, the remaining fields in struct cc_var are for use by mod_cc modules. let's go through them:
cc_dataโ available for algorithms requiring additional per-connection state to attach a dynamic memory pointer to. the memory should be allocated and attached in the module'scb_inithook function.bytes_this_ackโ specifies the number of new bytes acknowledged by the most recently received ACK packet. it is only valid in theack_receivedhook function. don't be using it elsewhere, bestie. ๐curackโ specifies the sequence number of the most recently received ACK packet. it is only valid in theack_received,cong_signalandpost_recoveryhook functions.flagsโ used to pass useful information from the stack to amod_ccmodule. two flags to know:CCF_ABC_SENTAWNDis relevant inack_receivedand is set when appropriate byte counting (RFC3465) has counted a window's worth of bytes has been sent. it is the module's responsibility to clear the flag after it has processed the signal.CCF_CWND_LIMITEDis relevant inack_receivedand is set when the connection's ability to send data is currently constrained by the value of the congestion window. algorithms should use the absence of this flag being set to avoid accumulating a large difference between the congestion window and send window.
๐ SEE ALSO ๐
cc_cdg(4), cc_chd(4), cc_cubic(4), cc_hd(4), cc_htcp(4), cc_newreno(4), cc_vegas(4), mod_cc(4), tcp(4)
๐ซถ ACKNOWLEDGEMENTS ๐ซถ
development and testing of this software were made possible in part by grants from the FreeBSD Foundation and Cisco University Research Program Fund at Community Foundation Silicon Valley. we love funding, we love research, we love it here. ๐
๐ฎ FUTURE WORK ๐ฎ
integrate with sctp(4).
that's it. that's the whole to-do list. manifesting it. โจ
๐ HISTORY ๐
the modular Congestion Control (CC) framework first appeared in FreeBSD 9.0.
the framework was first released in 2007 by James Healy and Lawrence Stewart whilst working on the NewTCP research project at Swinburne University of Technology's Centre for Advanced Internet Architectures, Melbourne, Australia โ which was made possible in part by a grant from the Cisco University Research Program Fund at Community Foundation Silicon Valley. more details are available at:
http://caia.swin.edu.au/urp/newtcp/
๐ AUTHORS ๐
the mod_cc framework was written by Lawrence Stewart <lstewart@FreeBSD.org>, James Healy <jimmy@deefa.com> and David Hayes <david.hayes@ieee.org>.
this manual page was written by David Hayes <david.hayes@ieee.org> and Lawrence Stewart <lstewart@FreeBSD.org>.
and that's the whole page, bestie! ๐ this came to you courtesy of Debian, dated January 21, 2016 โ yes, a January 2016 release on Debian, and it still ate. go build a congestion control module, you absolute icon. ๐ ๐๐
๐ฆ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 ยท BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 ยท BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 ยท BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 ยท BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 ยท BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 ยท BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2008-2009 Lawrence Stewart <lstewart@FreeBSD.org>
- Copyright (c) 2010-2011 The FreeBSD Foundation
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms