]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* |
508e53e2 | 2 | * Copyright (C) 2003 Yasuhiro Ohara |
718e3744 | 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 | * | |
896014f4 DL |
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 | |
718e3744 | 19 | */ |
20 | ||
21 | #include <zebra.h> | |
22 | ||
508e53e2 | 23 | #include "log.h" |
24 | ||
718e3744 | 25 | #include "ospf6_proto.h" |
26 | ||
b8ce0c36 | 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 | ||
d62a17ae | 37 | void ospf6_prefix_apply_mask(struct ospf6_prefix *op) |
718e3744 | 38 | { |
d7c0a89a | 39 | uint8_t *pnt, mask; |
d62a17ae | 40 | int index, offset; |
508e53e2 | 41 | |
d7c0a89a | 42 | pnt = (uint8_t *)((caddr_t)op + sizeof(struct ospf6_prefix)); |
d62a17ae | 43 | index = op->prefix_length / 8; |
44 | offset = op->prefix_length % 8; | |
45 | mask = 0xff << (8 - offset); | |
508e53e2 | 46 | |
d62a17ae | 47 | if (index > 16) { |
48 | zlog_warn("Prefix length too long: %d", op->prefix_length); | |
49 | return; | |
50 | } | |
508e53e2 | 51 | |
d62a17ae | 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; | |
508e53e2 | 56 | |
d62a17ae | 57 | while (index < OSPF6_PREFIX_SPACE(op->prefix_length)) |
58 | pnt[index++] = 0; | |
508e53e2 | 59 | } |
60 | ||
d7c0a89a | 61 | void ospf6_prefix_options_printbuf(uint8_t prefix_options, char *buf, int size) |
508e53e2 | 62 | { |
d62a17ae | 63 | snprintf(buf, size, "xxx"); |
508e53e2 | 64 | } |
65 | ||
d62a17ae | 66 | void ospf6_capability_printbuf(char capability, char *buf, int size) |
508e53e2 | 67 | { |
d62a17ae | 68 | char w, v, e, b; |
69 | w = (capability & OSPF6_ROUTER_BIT_W ? 'W' : '-'); | |
70 | v = (capability & OSPF6_ROUTER_BIT_V ? 'V' : '-'); | |
71 | e = (capability & OSPF6_ROUTER_BIT_E ? 'E' : '-'); | |
72 | b = (capability & OSPF6_ROUTER_BIT_B ? 'B' : '-'); | |
73 | snprintf(buf, size, "----%c%c%c%c", w, v, e, b); | |
508e53e2 | 74 | } |
718e3744 | 75 | |
d7c0a89a | 76 | void ospf6_options_printbuf(uint8_t *options, char *buf, int size) |
508e53e2 | 77 | { |
d62a17ae | 78 | const char *dc, *r, *n, *mc, *e, *v6; |
79 | dc = (OSPF6_OPT_ISSET(options, OSPF6_OPT_DC) ? "DC" : "--"); | |
80 | r = (OSPF6_OPT_ISSET(options, OSPF6_OPT_R) ? "R" : "-"); | |
81 | n = (OSPF6_OPT_ISSET(options, OSPF6_OPT_N) ? "N" : "-"); | |
82 | mc = (OSPF6_OPT_ISSET(options, OSPF6_OPT_MC) ? "MC" : "--"); | |
83 | e = (OSPF6_OPT_ISSET(options, OSPF6_OPT_E) ? "E" : "-"); | |
84 | v6 = (OSPF6_OPT_ISSET(options, OSPF6_OPT_V6) ? "V6" : "--"); | |
85 | snprintf(buf, size, "%s|%s|%s|%s|%s|%s", dc, r, n, mc, e, v6); | |
718e3744 | 86 | } |