Line data Source code
1 : /*
2 : * Copyright (C) 2003 Yasuhiro Ohara
3 : *
4 : * This file is part of GNU Zebra.
5 : *
6 : * GNU Zebra is free software; you can redistribute it and/or modify it
7 : * under the terms of the GNU General Public License as published by the
8 : * Free Software Foundation; either version 2, or (at your option) any
9 : * later version.
10 : *
11 : * GNU Zebra is distributed in the hope that it will be useful, but
12 : * WITHOUT ANY WARRANTY; without even the implied warranty of
13 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 : * General Public License for more details.
15 : *
16 : * You should have received a copy of the GNU General Public License along
17 : * with this program; see the file COPYING; if not, write to the Free Software
18 : * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 : */
20 :
21 : #include <zebra.h>
22 :
23 : #include "log.h"
24 :
25 : #include "ospf6_proto.h"
26 :
27 643 : void ospf6_prefix_in6_addr(struct in6_addr *in6, const void *prefix_buf,
28 : const struct ospf6_prefix *p)
29 : {
30 643 : ptrdiff_t in6_off = (caddr_t)p->addr - (caddr_t)prefix_buf;
31 :
32 643 : memset(in6, 0, sizeof(struct in6_addr));
33 643 : memcpy(in6, (uint8_t *)prefix_buf + in6_off,
34 643 : OSPF6_PREFIX_SPACE(p->prefix_length));
35 643 : }
36 :
37 92 : void ospf6_prefix_apply_mask(struct ospf6_prefix *op)
38 : {
39 92 : uint8_t *pnt, mask;
40 92 : int index, offset;
41 :
42 92 : pnt = (uint8_t *)((caddr_t)op + sizeof(struct ospf6_prefix));
43 92 : index = op->prefix_length / 8;
44 92 : offset = op->prefix_length % 8;
45 92 : mask = 0xff << (8 - offset);
46 :
47 92 : if (index > 16) {
48 0 : zlog_warn("Prefix length too long: %d", op->prefix_length);
49 0 : return;
50 : }
51 :
52 : /* nonzero mask means no check for this byte because if it contains
53 : * prefix bits it must be there for us to write */
54 92 : if (mask)
55 0 : pnt[index++] &= mask;
56 :
57 92 : while (index < OSPF6_PREFIX_SPACE(op->prefix_length))
58 0 : pnt[index++] = 0;
59 : }
60 :
61 0 : void ospf6_prefix_options_printbuf(uint8_t prefix_options, char *buf, int size)
62 : {
63 0 : const char *dn, *p, *mc, *la, *nu;
64 :
65 0 : dn = (CHECK_FLAG(prefix_options, OSPF6_PREFIX_OPTION_DN) ? "DN" : "--");
66 0 : p = (CHECK_FLAG(prefix_options, OSPF6_PREFIX_OPTION_P) ? "P" : "--");
67 0 : mc = (CHECK_FLAG(prefix_options, OSPF6_PREFIX_OPTION_MC) ? "MC" : "--");
68 0 : la = (CHECK_FLAG(prefix_options, OSPF6_PREFIX_OPTION_LA) ? "LA" : "--");
69 0 : nu = (CHECK_FLAG(prefix_options, OSPF6_PREFIX_OPTION_NU) ? "NU" : "--");
70 0 : snprintf(buf, size, "%s|%s|%s|%s|%s", dn, p, mc, la, nu);
71 0 : }
72 :
73 0 : void ospf6_capability_printbuf(char capability, char *buf, int size)
74 : {
75 0 : char w, v, e, b;
76 0 : w = (capability & OSPF6_ROUTER_BIT_W ? 'W' : '-');
77 0 : v = (capability & OSPF6_ROUTER_BIT_V ? 'V' : '-');
78 0 : e = (capability & OSPF6_ROUTER_BIT_E ? 'E' : '-');
79 0 : b = (capability & OSPF6_ROUTER_BIT_B ? 'B' : '-');
80 0 : snprintf(buf, size, "----%c%c%c%c", w, v, e, b);
81 0 : }
82 :
83 0 : void ospf6_options_printbuf(uint8_t *options, char *buf, int size)
84 : {
85 0 : const char *dc, *r, *n, *mc, *e, *v6, *af, *at, *l;
86 0 : dc = (OSPF6_OPT_ISSET(options, OSPF6_OPT_DC) ? "DC" : "--");
87 0 : r = (OSPF6_OPT_ISSET(options, OSPF6_OPT_R) ? "R" : "-");
88 0 : n = (OSPF6_OPT_ISSET(options, OSPF6_OPT_N) ? "N" : "-");
89 0 : mc = (OSPF6_OPT_ISSET(options, OSPF6_OPT_MC) ? "MC" : "--");
90 0 : e = (OSPF6_OPT_ISSET(options, OSPF6_OPT_E) ? "E" : "-");
91 0 : v6 = (OSPF6_OPT_ISSET(options, OSPF6_OPT_V6) ? "V6" : "--");
92 0 : af = (OSPF6_OPT_ISSET_EXT(options, OSPF6_OPT_AF) ? "AF" : "--");
93 0 : at = (OSPF6_OPT_ISSET_EXT(options, OSPF6_OPT_AT) ? "AT" : "--");
94 0 : l = (OSPF6_OPT_ISSET_EXT(options, OSPF6_OPT_L) ? "L" : "-");
95 0 : snprintf(buf, size, "%s|%s|%s|-|-|%s|%s|%s|%s|%s|%s", at, l, af, dc, r,
96 : n, mc, e, v6);
97 0 : }
|