]> git.proxmox.com Git - mirror_frr.git/blame - ospf6d/ospf6_proto.c
Merge pull request #13641 from donaldsharp/com_list_str
[mirror_frr.git] / ospf6d / ospf6_proto.c
CommitLineData
acddc0ed 1// SPDX-License-Identifier: GPL-2.0-or-later
718e3744 2/*
508e53e2 3 * Copyright (C) 2003 Yasuhiro Ohara
718e3744 4 */
5
6#include <zebra.h>
7
508e53e2 8#include "log.h"
9
718e3744 10#include "ospf6_proto.h"
11
b8ce0c36 12void ospf6_prefix_in6_addr(struct in6_addr *in6, const void *prefix_buf,
13 const struct ospf6_prefix *p)
14{
15 ptrdiff_t in6_off = (caddr_t)p->addr - (caddr_t)prefix_buf;
16
17 memset(in6, 0, sizeof(struct in6_addr));
18 memcpy(in6, (uint8_t *)prefix_buf + in6_off,
19 OSPF6_PREFIX_SPACE(p->prefix_length));
20}
21
d62a17ae 22void ospf6_prefix_apply_mask(struct ospf6_prefix *op)
718e3744 23{
d7c0a89a 24 uint8_t *pnt, mask;
d62a17ae 25 int index, offset;
508e53e2 26
d7c0a89a 27 pnt = (uint8_t *)((caddr_t)op + sizeof(struct ospf6_prefix));
d62a17ae 28 index = op->prefix_length / 8;
29 offset = op->prefix_length % 8;
30 mask = 0xff << (8 - offset);
508e53e2 31
d62a17ae 32 if (index > 16) {
33 zlog_warn("Prefix length too long: %d", op->prefix_length);
34 return;
35 }
508e53e2 36
d62a17ae 37 /* nonzero mask means no check for this byte because if it contains
38 * prefix bits it must be there for us to write */
39 if (mask)
40 pnt[index++] &= mask;
508e53e2 41
d62a17ae 42 while (index < OSPF6_PREFIX_SPACE(op->prefix_length))
43 pnt[index++] = 0;
508e53e2 44}
45
d7c0a89a 46void ospf6_prefix_options_printbuf(uint8_t prefix_options, char *buf, int size)
508e53e2 47{
600d28e3 48 const char *dn, *p, *mc, *la, *nu;
66721aae 49
600d28e3 50 dn = (CHECK_FLAG(prefix_options, OSPF6_PREFIX_OPTION_DN) ? "DN" : "--");
51 p = (CHECK_FLAG(prefix_options, OSPF6_PREFIX_OPTION_P) ? "P" : "--");
52 mc = (CHECK_FLAG(prefix_options, OSPF6_PREFIX_OPTION_MC) ? "MC" : "--");
53 la = (CHECK_FLAG(prefix_options, OSPF6_PREFIX_OPTION_LA) ? "LA" : "--");
54 nu = (CHECK_FLAG(prefix_options, OSPF6_PREFIX_OPTION_NU) ? "NU" : "--");
55 snprintf(buf, size, "%s|%s|%s|%s|%s", dn, p, mc, la, nu);
508e53e2 56}
57
d62a17ae 58void ospf6_capability_printbuf(char capability, char *buf, int size)
508e53e2 59{
d62a17ae 60 char w, v, e, b;
61 w = (capability & OSPF6_ROUTER_BIT_W ? 'W' : '-');
62 v = (capability & OSPF6_ROUTER_BIT_V ? 'V' : '-');
63 e = (capability & OSPF6_ROUTER_BIT_E ? 'E' : '-');
64 b = (capability & OSPF6_ROUTER_BIT_B ? 'B' : '-');
65 snprintf(buf, size, "----%c%c%c%c", w, v, e, b);
508e53e2 66}
718e3744 67
d7c0a89a 68void ospf6_options_printbuf(uint8_t *options, char *buf, int size)
508e53e2 69{
6cb85350 70 const char *dc, *r, *n, *mc, *e, *v6, *af, *at, *l;
d62a17ae 71 dc = (OSPF6_OPT_ISSET(options, OSPF6_OPT_DC) ? "DC" : "--");
72 r = (OSPF6_OPT_ISSET(options, OSPF6_OPT_R) ? "R" : "-");
73 n = (OSPF6_OPT_ISSET(options, OSPF6_OPT_N) ? "N" : "-");
74 mc = (OSPF6_OPT_ISSET(options, OSPF6_OPT_MC) ? "MC" : "--");
75 e = (OSPF6_OPT_ISSET(options, OSPF6_OPT_E) ? "E" : "-");
76 v6 = (OSPF6_OPT_ISSET(options, OSPF6_OPT_V6) ? "V6" : "--");
6cb85350
AR
77 af = (OSPF6_OPT_ISSET_EXT(options, OSPF6_OPT_AF) ? "AF" : "--");
78 at = (OSPF6_OPT_ISSET_EXT(options, OSPF6_OPT_AT) ? "AT" : "--");
79 l = (OSPF6_OPT_ISSET_EXT(options, OSPF6_OPT_L) ? "L" : "-");
80 snprintf(buf, size, "%s|%s|%s|-|-|%s|%s|%s|%s|%s|%s", at, l, af, dc, r,
81 n, mc, e, v6);
718e3744 82}