]>
git.proxmox.com Git - mirror_frr.git/blob - lib/xref.c
2 * Copyright (c) 2017-20 David Lamparter, for NetDEF, Inc.
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
35 struct xref_block
*xref_blocks
;
36 static struct xref_block
**xref_block_last
= &xref_blocks
;
38 static void base32(uint8_t **inpos
, int *bitpos
,
39 char *out
, size_t n_chars
)
41 static const char base32ch
[] = "0123456789ABCDEFGHJKMNPQRSTVWXYZ";
47 while (opos
< out
+ n_chars
) {
48 uint32_t bits
= in
[0] | (in
[1] << 8);
55 *opos
++ = base32ch
[bits
& 0x1f];
66 static void xref_add_one(const struct xref
*xref
)
69 struct xrefdata
*xrefdata
;
71 const char *filename
, *p
, *q
;
72 uint8_t hash
[32], *h
= hash
;
76 if (!xref
|| !xref
->xrefdata
)
79 xrefdata
= xref
->xrefdata
;
80 xrefdata
->xref
= xref
;
82 if (!xrefdata
->hashstr
)
85 /* as far as the unique ID is concerned, only use the last
86 * directory name + filename, e.g. "bgpd/bgp_route.c". This
87 * gives a little leeway in moving things and avoids IDs being
88 * screwed up by out of tree builds or absolute pathnames.
90 filename
= xref
->file
;
91 p
= strrchr(filename
, '/');
93 q
= memrchr(filename
, '/', p
- filename
);
99 SHA256_Update(&sha
, filename
, strlen(filename
));
100 SHA256_Update(&sha
, xrefdata
->hashstr
,
101 strlen(xrefdata
->hashstr
));
102 be_val
= htonl(xrefdata
->hashu32
[0]);
103 SHA256_Update(&sha
, &be_val
, sizeof(be_val
));
104 be_val
= htonl(xrefdata
->hashu32
[1]);
105 SHA256_Update(&sha
, &be_val
, sizeof(be_val
));
106 SHA256_Final(hash
, &sha
);
109 base32(&h
, &bitpos
, &xrefdata
->uid
[0], 5);
110 xrefdata
->uid
[5] = '-';
111 base32(&h
, &bitpos
, &xrefdata
->uid
[6], 5);
114 void xref_gcc_workaround(const struct xref
*xref
)
119 void xref_block_add(struct xref_block
*block
)
121 const struct xref
* const *xrefp
;
123 *xref_block_last
= block
;
124 xref_block_last
= &block
->next
;
126 for (xrefp
= block
->start
; xrefp
< block
->stop
; xrefp
++)
127 xref_add_one(*xrefp
);