| 778 | } |
| 779 | |
| 780 | static int |
| 781 | carp_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 |
no test coverage detected