]> git.proxmox.com Git - mirror_frr.git/blob - ospf6d/ospf6_proto.c
4d0c4ee59ec2d7c6e1357e7529537b10bb9ba409
[mirror_frr.git] / ospf6d / ospf6_proto.c
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 void ospf6_prefix_in6_addr(struct in6_addr *in6, const void *prefix_buf,
28 const struct ospf6_prefix *p)
29 {
30 ptrdiff_t in6_off = (caddr_t)p->addr - (caddr_t)prefix_buf;
31
32 memset(in6, 0, sizeof(struct in6_addr));
33 memcpy(in6, (uint8_t *)prefix_buf + in6_off,
34 OSPF6_PREFIX_SPACE(p->prefix_length));
35 }
36
37 void ospf6_prefix_apply_mask(struct ospf6_prefix *op)
38 {
39 uint8_t *pnt, mask;
40 int index, offset;
41
42 pnt = (uint8_t *)((caddr_t)op + sizeof(struct ospf6_prefix));
43 index = op->prefix_length / 8;
44 offset = op->prefix_length % 8;
45 mask = 0xff << (8 - offset);
46
47 if (index > 16) {
48 zlog_warn("Prefix length too long: %d", op->prefix_length);
49 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 if (mask)
55 pnt[index++] &= mask;
56
57 while (index < OSPF6_PREFIX_SPACE(op->prefix_length))
58 pnt[index++] = 0;
59 }
60
61 void ospf6_prefix_options_printbuf(uint8_t prefix_options, char *buf, int size)
62 {
63 const char *dn, *p, *mc, *la, *nu;
64
65 dn = (CHECK_FLAG(prefix_options, OSPF6_PREFIX_OPTION_DN) ? "DN" : "--");
66 p = (CHECK_FLAG(prefix_options, OSPF6_PREFIX_OPTION_P) ? "P" : "--");
67 mc = (CHECK_FLAG(prefix_options, OSPF6_PREFIX_OPTION_MC) ? "MC" : "--");
68 la = (CHECK_FLAG(prefix_options, OSPF6_PREFIX_OPTION_LA) ? "LA" : "--");
69 nu = (CHECK_FLAG(prefix_options, OSPF6_PREFIX_OPTION_NU) ? "NU" : "--");
70 snprintf(buf, size, "%s|%s|%s|%s|%s", dn, p, mc, la, nu);
71 }
72
73 void ospf6_capability_printbuf(char capability, char *buf, int size)
74 {
75 char w, v, e, b;
76 w = (capability & OSPF6_ROUTER_BIT_W ? 'W' : '-');
77 v = (capability & OSPF6_ROUTER_BIT_V ? 'V' : '-');
78 e = (capability & OSPF6_ROUTER_BIT_E ? 'E' : '-');
79 b = (capability & OSPF6_ROUTER_BIT_B ? 'B' : '-');
80 snprintf(buf, size, "----%c%c%c%c", w, v, e, b);
81 }
82
83 void ospf6_options_printbuf(uint8_t *options, char *buf, int size)
84 {
85 const char *dc, *r, *n, *mc, *e, *v6, *af, *at, *l;
86 dc = (OSPF6_OPT_ISSET(options, OSPF6_OPT_DC) ? "DC" : "--");
87 r = (OSPF6_OPT_ISSET(options, OSPF6_OPT_R) ? "R" : "-");
88 n = (OSPF6_OPT_ISSET(options, OSPF6_OPT_N) ? "N" : "-");
89 mc = (OSPF6_OPT_ISSET(options, OSPF6_OPT_MC) ? "MC" : "--");
90 e = (OSPF6_OPT_ISSET(options, OSPF6_OPT_E) ? "E" : "-");
91 v6 = (OSPF6_OPT_ISSET(options, OSPF6_OPT_V6) ? "V6" : "--");
92 af = (OSPF6_OPT_ISSET_EXT(options, OSPF6_OPT_AF) ? "AF" : "--");
93 at = (OSPF6_OPT_ISSET_EXT(options, OSPF6_OPT_AT) ? "AT" : "--");
94 l = (OSPF6_OPT_ISSET_EXT(options, OSPF6_OPT_L) ? "L" : "-");
95 snprintf(buf, size, "%s|%s|%s|-|-|%s|%s|%s|%s|%s|%s", at, l, af, dc, r,
96 n, mc, e, v6);
97 }