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

Function carp_prepare_ad

freebsd/netinet/ip_carp.c:780–809  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

778}
779
780static int
781carp_prepare_ad(struct mbuf *m, struct carp_softc *sc, struct carp_header *ch)
782{
783 struct m_tag *mtag;
784
785 if (sc->sc_init_counter) {
786 /* this could also be seconds since unix epoch */
787 sc->sc_counter = arc4random();
788 sc->sc_counter = sc->sc_counter << 32;
789 sc->sc_counter += arc4random();
790 } else
791 sc->sc_counter++;
792
793 ch->carp_counter[0] = htonl((sc->sc_counter>>32)&0xffffffff);
794 ch->carp_counter[1] = htonl(sc->sc_counter&0xffffffff);
795
796 carp_hmac_generate(sc, ch->carp_counter, ch->carp_md);
797
798 /* Tag packet for carp_output */
799 if ((mtag = m_tag_get(PACKET_TAG_CARP, sizeof(struct carp_softc *),
800 M_NOWAIT)) == NULL) {
801 m_freem(m);
802 CARPSTATS_INC(carps_onomem);
803 return (ENOMEM);
804 }
805 bcopy(&sc, mtag + 1, sizeof(sc));
806 m_tag_prepend(m, mtag);
807
808 return (0);
809}
810
811/*
812 * To avoid LORs and possible recursions this function shouldn't

Callers 1

carp_send_ad_lockedFunction · 0.85

Calls 5

carp_hmac_generateFunction · 0.85
arc4randomFunction · 0.50
m_tag_getFunction · 0.50
m_freemFunction · 0.50
m_tag_prependFunction · 0.50

Tested by

no test coverage detected