paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * OSPF Sending and Receiving OSPF Packets. |
| 3 | * Copyright (C) 1999 Toshiaki Takada |
| 4 | * |
| 5 | * This file is part of GNU Zebra. |
| 6 | * |
| 7 | * GNU Zebra is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2, or (at your option) any |
| 10 | * later version. |
| 11 | * |
| 12 | * GNU Zebra is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with GNU Zebra; see the file COPYING. If not, write to the Free |
| 19 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 20 | * 02111-1307, USA. |
| 21 | */ |
| 22 | |
| 23 | #ifndef _ZEBRA_OSPF_PACKET_H |
| 24 | #define _ZEBRA_OSPF_PACKET_H |
| 25 | |
paul | 6c83567 | 2004-10-11 11:00:30 +0000 | [diff] [blame] | 26 | #define OSPF_HEADER_SIZE 24U |
| 27 | #define OSPF_AUTH_SIMPLE_SIZE 8U |
| 28 | #define OSPF_AUTH_MD5_SIZE 16U |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 29 | |
paul | 6c83567 | 2004-10-11 11:00:30 +0000 | [diff] [blame] | 30 | #define OSPF_MAX_PACKET_SIZE 65535U /* includes IP Header size. */ |
| 31 | #define OSPF_HELLO_MIN_SIZE 20U /* not including neighbors */ |
| 32 | #define OSPF_DB_DESC_MIN_SIZE 8U |
| 33 | #define OSPF_LS_REQ_MIN_SIZE 0U |
| 34 | #define OSPF_LS_UPD_MIN_SIZE 4U |
| 35 | #define OSPF_LS_ACK_MIN_SIZE 0U |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 36 | |
| 37 | #define OSPF_MSG_HELLO 1 /* OSPF Hello Message. */ |
| 38 | #define OSPF_MSG_DB_DESC 2 /* OSPF Database Descriptoin Message. */ |
| 39 | #define OSPF_MSG_LS_REQ 3 /* OSPF Link State Request Message. */ |
| 40 | #define OSPF_MSG_LS_UPD 4 /* OSPF Link State Update Message. */ |
| 41 | #define OSPF_MSG_LS_ACK 5 /* OSPF Link State Acknoledgement Message. */ |
| 42 | |
| 43 | #define OSPF_SEND_PACKET_DIRECT 1 |
| 44 | #define OSPF_SEND_PACKET_INDIRECT 2 |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 45 | #define OSPF_SEND_PACKET_LOOP 3 |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 46 | |
| 47 | #define OSPF_HELLO_REPLY_DELAY 1 |
| 48 | |
| 49 | struct ospf_packet |
| 50 | { |
| 51 | struct ospf_packet *next; |
| 52 | |
| 53 | /* Pointer to data stream. */ |
| 54 | struct stream *s; |
| 55 | |
| 56 | /* IP destination address. */ |
| 57 | struct in_addr dst; |
| 58 | |
| 59 | /* OSPF packet length. */ |
| 60 | u_int16_t length; |
| 61 | }; |
| 62 | |
| 63 | /* OSPF packet queue structure. */ |
| 64 | struct ospf_fifo |
| 65 | { |
| 66 | unsigned long count; |
| 67 | |
| 68 | struct ospf_packet *head; |
| 69 | struct ospf_packet *tail; |
| 70 | }; |
| 71 | |
| 72 | /* OSPF packet header structure. */ |
| 73 | struct ospf_header |
| 74 | { |
| 75 | u_char version; /* OSPF Version. */ |
| 76 | u_char type; /* Packet Type. */ |
| 77 | u_int16_t length; /* Packet Length. */ |
| 78 | struct in_addr router_id; /* Router ID. */ |
| 79 | struct in_addr area_id; /* Area ID. */ |
| 80 | u_int16_t checksum; /* Check Sum. */ |
| 81 | u_int16_t auth_type; /* Authentication Type. */ |
| 82 | /* Authentication Data. */ |
| 83 | union |
| 84 | { |
| 85 | /* Simple Authentication. */ |
| 86 | u_char auth_data [OSPF_AUTH_SIMPLE_SIZE]; |
| 87 | /* Cryptographic Authentication. */ |
| 88 | struct |
| 89 | { |
| 90 | u_int16_t zero; /* Should be 0. */ |
| 91 | u_char key_id; /* Key ID. */ |
| 92 | u_char auth_data_len; /* Auth Data Length. */ |
| 93 | u_int32_t crypt_seqnum; /* Cryptographic Sequence Number. */ |
| 94 | } crypt; |
| 95 | } u; |
| 96 | }; |
| 97 | |
| 98 | /* OSPF Hello body format. */ |
| 99 | struct ospf_hello |
| 100 | { |
| 101 | struct in_addr network_mask; |
| 102 | u_int16_t hello_interval; |
| 103 | u_char options; |
| 104 | u_char priority; |
| 105 | u_int32_t dead_interval; |
| 106 | struct in_addr d_router; |
| 107 | struct in_addr bd_router; |
| 108 | struct in_addr neighbors[1]; |
| 109 | }; |
| 110 | |
| 111 | /* OSPF Database Description body format. */ |
| 112 | struct ospf_db_desc |
| 113 | { |
| 114 | u_int16_t mtu; |
| 115 | u_char options; |
| 116 | u_char flags; |
| 117 | u_int32_t dd_seqnum; |
| 118 | }; |
| 119 | |
| 120 | |
| 121 | /* Macros. */ |
| 122 | #define OSPF_PACKET_MAX(oi) ospf_packet_max (oi) |
| 123 | /* |
| 124 | #define OSPF_PACKET_MAX(oi) (((oi)->ifp->mtu - ((oi)->auth_md5 ? OSPF_AUTH_MD5_SIZE : 0)) - 88) |
| 125 | */ |
| 126 | |
| 127 | #define OSPF_OUTPUT_PNT(S) ((S)->data + (S)->putp) |
| 128 | #define OSPF_OUTPUT_LENGTH(S) ((S)->endp) |
| 129 | |
| 130 | #define IS_SET_DD_MS(X) ((X) & OSPF_DD_FLAG_MS) |
| 131 | #define IS_SET_DD_M(X) ((X) & OSPF_DD_FLAG_M) |
| 132 | #define IS_SET_DD_I(X) ((X) & OSPF_DD_FLAG_I) |
| 133 | #define IS_SET_DD_ALL(X) ((X) & OSPF_DD_FLAG_ALL) |
| 134 | |
| 135 | /* Prototypes. */ |
| 136 | void ospf_output_forward (struct stream *, int); |
| 137 | struct ospf_packet *ospf_packet_new (size_t); |
| 138 | void ospf_packet_free (struct ospf_packet *); |
| 139 | struct ospf_fifo *ospf_fifo_new (); |
| 140 | void ospf_fifo_push (struct ospf_fifo *, struct ospf_packet *); |
| 141 | struct ospf_packet *ospf_fifo_pop (struct ospf_fifo *); |
| 142 | struct ospf_packet *ospf_fifo_head (struct ospf_fifo *); |
| 143 | void ospf_fifo_flush (struct ospf_fifo *); |
| 144 | void ospf_fifo_free (struct ospf_fifo *); |
| 145 | void ospf_packet_add (struct ospf_interface *, struct ospf_packet *); |
| 146 | void ospf_packet_delete (struct ospf_interface *); |
| 147 | struct stream *ospf_stream_dup (struct stream *); |
| 148 | struct ospf_packet *ospf_packet_dup (struct ospf_packet *); |
| 149 | |
| 150 | int ospf_read (struct thread *); |
| 151 | void ospf_hello_send (struct ospf_interface *); |
| 152 | void ospf_db_desc_send (struct ospf_neighbor *); |
| 153 | void ospf_db_desc_resend (struct ospf_neighbor *); |
| 154 | void ospf_ls_req_send (struct ospf_neighbor *); |
| 155 | void ospf_ls_upd_send_lsa (struct ospf_neighbor *, struct ospf_lsa *, int); |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 156 | void ospf_ls_upd_send (struct ospf_neighbor *, struct list *, int); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 157 | void ospf_ls_ack_send (struct ospf_neighbor *, struct ospf_lsa *); |
| 158 | void ospf_ls_ack_send_delayed (struct ospf_interface *); |
| 159 | void ospf_ls_retransmit (struct ospf_interface *, struct ospf_lsa *); |
| 160 | void ospf_ls_req_event (struct ospf_neighbor *); |
| 161 | |
| 162 | int ospf_ls_upd_timer (struct thread *); |
| 163 | int ospf_ls_ack_timer (struct thread *); |
| 164 | int ospf_poll_timer (struct thread *); |
| 165 | int ospf_hello_reply_timer (struct thread *); |
| 166 | void ospf_hello_send_sub (struct ospf_interface *, struct in_addr *); |
| 167 | |
| 168 | #endif /* _ZEBRA_OSPF_PACKET_H */ |