Revision 48e5f32d

View differences:

doc/bird.sgml
2212 2212
			wait <num>;
2213 2213
			dead count <num>;
2214 2214
			dead <num>;
2215
			secondary <switch>;
2215 2216
			rx buffer [normal|large|<num>];
2217
			tx length <num>;
2216 2218
			type [broadcast|bcast|pointopoint|ptp|
2217 2219
				nonbroadcast|nbma|pointomultipoint|ptmp];
2218 2220
			strict nonbroadcast <switch>;
......
2419 2421
	<tag>dead <M>num</M></tag>
2420 2422
	 When the router does not receive any messages from a neighbor in
2421 2423
	 <m/dead/ seconds, it will consider the neighbor down. If both directives
2422
	 <m/dead count/ and <m/dead/ are used, <m/dead/ has precendence.
2424
	 <cf/dead count/ and <cf/dead/ are used, <cf/dead/ has precendence.
2425

  
2426
	<tag>secondary <M>switch</M></tag>
2427
	On BSD systems, older versions of BIRD supported OSPFv2 only for the
2428
	primary IP address of an interface, other IP ranges on the interface
2429
	were handled as stub networks. Since v1.4.1, regular operation on
2430
	secondary IP addresses is supported, but disabled by default for
2431
	compatibility. This option allows to enable it. The option is a
2432
	transitional measure, will be removed in the next major release as the
2433
	behavior will be changed. On Linux systems, the option is irrelevant, as
2434
	operation on non-primary addresses is already the regular behavior.
2423 2435

  
2424 2436
	<tag>rx buffer <M>num</M></tag>
2425
	 This sets the size of buffer used for receiving packets. The buffer should
2426
	 be bigger than maximal size of any packets. Value NORMAL (default)
2427
	 means 2*MTU, value LARGE means maximal allowed packet - 65535.
2437
	This option allows to specify the size of buffers used for packet
2438
	processing. The buffer size should be bigger than maximal size of any
2439
	packets. By default, buffers are dynamically resized as needed, but a
2440
	fixed value could be specified. Value <cf/large/ means maximal allowed
2441
	packet size - 65535.
2442

  
2443
	<tag>tx length <M>num</M></tag>
2444
	Transmitted OSPF messages that contain large amount of information are
2445
	segmented to separate OSPF packets to avoid IP fragmentation. This
2446
	option specifies the soft ceiling for the length of generated OSPF
2447
	packets. Default value is the MTU of the network interface. Note that
2448
	larger OSPF packets may still be generated if underlying OSPF messages
2449
	cannot be splitted (e.g. when one large LSA is propagated).
2428 2450

  
2429 2451
	<tag>type broadcast|bcast</tag>
2430 2452
	 BIRD detects a type of a connected network automatically, but
lib/resource.c
157 157
{
158 158
  resource *r = res;
159 159

  
160
  if (r)
161
    {
162
      if (r->n.next)
163
	rem_node(&r->n);
164
      r->class->free(r);
165
      xfree(r);
166
    }
160
  if (!r)
161
    return;
162

  
163
  if (r->n.next)
164
    rem_node(&r->n);
165
  r->class->free(r);
166
  xfree(r);
167 167
}
168 168

  
169 169
/**
......
408 408
void
409 409
mb_free(void *m)
410 410
{
411
  if (!m)
412
    return;
413

  
411 414
  struct mblock *b = SKIP_BACK(struct mblock, data, m);
412 415
  rfree(b);
413 416
}
lib/socket.h
57 57
int sk_send(sock *, unsigned len);	/* Send data, <0=err, >0=ok, 0=sleep */
58 58
int sk_send_to(sock *, unsigned len, ip_addr to, unsigned port); /* sk_send to given destination */
59 59
void sk_reallocate(sock *);		/* Free and allocate tbuf & rbuf */
60
void sk_set_rbsize(sock *s, uint val);	/* Resize RX buffer */
61
void sk_set_tbsize(sock *s, uint val);	/* Resize TX buffer, keeping content */
62
void sk_set_tbuf(sock *s, void *tbuf);	/* Switch TX buffer, NULL-> return to internal */
60 63
void sk_dump_all(void);
61 64
int sk_set_ttl(sock *s, int ttl);	/* Set transmit TTL for given socket */
62 65
int sk_set_min_ttl(sock *s, int ttl);	/* Set minimal accepted TTL for given socket */
......
89 92

  
90 93
#define SKF_V6ONLY	1	/* Use IPV6_V6ONLY socket option */
91 94
#define SKF_LADDR_RX	2	/* Report local address for RX packets */
92
#define SKF_LADDR_TX	4	/* Allow to specify local address for TX packets */
93
#define SKF_TTL_RX	8	/* Report TTL / Hop Limit for RX packets */
95
#define SKF_TTL_RX	4	/* Report TTL / Hop Limit for RX packets */
96
#define SKF_BIND	8	/* Bind datagram socket to given source address */
94 97

  
95 98
#define SKF_THREAD	0x100	/* Socked used in thread, Do not add to main loop */
99
#define SKF_TRUNCATED	0x200	/* Received packet was truncated, set by IO layer */
100
#define SKF_HDRINCL	0x400	/* Used internally */
101
#define SKF_PKTINFO	0x800	/* Used internally */
96 102

  
97 103
/*
98 104
 *	Socket types		     SA SP DA DP IF  TTL SendTo	(?=may, -=must not, *=must)
......
118 124
 *  call sk_setup_multicast() to enable multicast on that socket,
119 125
 *  and then use sk_join_group() and sk_leave_group() to manage
120 126
 *  a set of received multicast groups.
127
 *
128
 *  For datagram (SK_UDP, SK_IP) sockets, there are two ways to handle
129
 *  source address. The socket could be bound to it using bind()
130
 *  syscall, but that also forbids the reception of multicast packets,
131
 *  or the address could be set on per-packet basis using platform
132
 *  dependent options (but these are not available in some corner
133
 *  cases). The first way is used when SKF_BIND is specified, the
134
 *  second way is used otherwise.
121 135
 */
122 136

  
123 137
#endif
proto/bfd/packets.c
230 230
  sk->tos = IP_PREC_INTERNET_CONTROL;
231 231
  sk->priority = sk_priority_control;
232 232
  sk->ttl = ifa ? 255 : -1;
233
  sk->flags = SKF_THREAD;
233
  sk->flags = SKF_THREAD | SKF_BIND;
234 234

  
235 235
#ifdef IPV6
236 236
  sk->flags |= SKF_V6ONLY;
proto/ospf/config.Y
131 131
CF_KEYWORDS(ELIGIBLE, POLL, NETWORKS, HIDDEN, VIRTUAL, CHECK, LINK, ONLY, BFD)
132 132
CF_KEYWORDS(RX, BUFFER, LARGE, NORMAL, STUBNET, HIDDEN, SUMMARY, TAG, EXTERNAL)
133 133
CF_KEYWORDS(WAIT, DELAY, LSADB, ECMP, LIMIT, WEIGHT, NSSA, TRANSLATOR, STABILITY)
134
CF_KEYWORDS(GLOBAL, LSID, ROUTER, SELF, INSTANCE, REAL, NETMASK, TX, PRIORITY)
134
CF_KEYWORDS(GLOBAL, LSID, ROUTER, SELF, INSTANCE, REAL, NETMASK, TX, PRIORITY, LENGTH)
135
CF_KEYWORDS(SECONDARY)
135 136

  
136 137
%type <t> opttext
137 138
%type <ld> lsadb_args
......
302 303
 | AUTHENTICATION NONE { OSPF_PATT->autype = OSPF_AUTH_NONE ; }
303 304
 | AUTHENTICATION SIMPLE { OSPF_PATT->autype = OSPF_AUTH_SIMPLE ; }
304 305
 | AUTHENTICATION CRYPTOGRAPHIC { OSPF_PATT->autype = OSPF_AUTH_CRYPT ; }
305
 | RX BUFFER LARGE { OSPF_PATT->rxbuf = OSPF_RXBUF_LARGE ; } 
306
 | RX BUFFER NORMAL { OSPF_PATT->rxbuf = OSPF_RXBUF_NORMAL ; } 
307
 | RX BUFFER expr { OSPF_PATT->rxbuf = $3 ; if (($3 < OSPF_RXBUF_MINSIZE) || ($3 > OSPF_MAX_PKT_SIZE)) cf_error("Buffer size must be in range 256-65535"); } 
306
 | RX BUFFER NORMAL { OSPF_PATT->rx_buffer = 0; } 
307
 | RX BUFFER LARGE { OSPF_PATT->rx_buffer = OSPF_MAX_PKT_SIZE; } 
308
 | RX BUFFER expr { OSPF_PATT->rx_buffer = $3; if (($3 < OSPF_MIN_PKT_SIZE) || ($3 > OSPF_MAX_PKT_SIZE)) cf_error("Buffer size must be in range 256-65535"); }
308 309
 | TX tos { OSPF_PATT->tx_tos = $2; }
309 310
 | TX PRIORITY expr { OSPF_PATT->tx_priority = $3; }
311
 | TX LENGTH expr { OSPF_PATT->tx_length = $3; if (($3 < OSPF_MIN_PKT_SIZE) || ($3 > OSPF_MAX_PKT_SIZE)) cf_error("TX length must be in range 256-65535"); }
310 312
 | TTL SECURITY bool { OSPF_PATT->ttl_security = $3; }
311 313
 | TTL SECURITY TX ONLY { OSPF_PATT->ttl_security = 2; }
312 314
 | BFD bool { OSPF_PATT->bfd = $2; cf_check_bfd($2); }
315
 | SECONDARY bool { OSPF_PATT->bsd_secondary = $2; }
313 316
 | password_list
314 317
 ;
315 318

  
proto/ospf/dbdes.c
103 103
    length = sizeof(struct ospf_dbdes_packet);
104 104
    op->length = htons(length);
105 105

  
106
    OSPF_PACKET(ospf_dump_dbdes, pkt, "DBDES packet sent to %I via %s", n->ip, ifa->iface->name);
106
    OSPF_PACKET(ospf_dump_dbdes, pkt, "DBDES packet sent to %I via %s", n->ip, ifa->ifname);
107 107
    ospf_send_to(ifa, n->ip);
108 108
    break;
109 109

  
......
115 115
      snode *sn;
116 116
      struct ospf_lsa_header *lsa;
117 117

  
118
      pkt = n->ldbdes;
118
      if (n->ldd_bsize != ifa->tx_length)
119
      {
120
	mb_free(n->ldd_buffer);
121
	n->ldd_buffer = mb_allocz(n->pool, ifa->tx_length);
122
	n->ldd_bsize = ifa->tx_length;
123
      }
124

  
125
      pkt = n->ldd_buffer;
119 126
      op = (struct ospf_packet *) pkt;
120 127

  
121 128
      ospf_pkt_fill_hdr(ifa, pkt, DBDES_P);
......
124 131
      pkt->options = hton_opt(oa->options);
125 132

  
126 133
      j = i = (ospf_pkt_maxsize(ifa) - sizeof(struct ospf_dbdes_packet)) / sizeof(struct ospf_lsa_header);	/* Number of possible lsaheaders to send */
127
      lsa = (n->ldbdes + sizeof(struct ospf_dbdes_packet));
134
      lsa = (n->ldd_buffer + sizeof(struct ospf_dbdes_packet));
128 135

  
129 136
      if (n->myimms.bit.m)
130 137
      {
......
175 182

  
176 183
  case NEIGHBOR_LOADING:
177 184
  case NEIGHBOR_FULL:
178
    length = ntohs(((struct ospf_packet *) n->ldbdes)->length);
185
    length = n->ldd_buffer ? ntohs(((struct ospf_packet *) n->ldd_buffer)->length) : 0;
179 186

  
180 187
    if (!length)
181 188
    {
......
184 191
      return;
185 192
    }
186 193

  
187
    /* Copy last sent packet again */
188
    pkt = ospf_tx_buffer(ifa);
189
    memcpy(pkt, n->ldbdes, length);
194
    /* Send last packet from ldd buffer */
190 195

  
191
    OSPF_PACKET(ospf_dump_dbdes, pkt, "DBDES packet sent to %I via %s", n->ip, ifa->iface->name);
196
    OSPF_PACKET(ospf_dump_dbdes, n->ldd_buffer, "DBDES packet sent to %I via %s", n->ip, ifa->ifname);
197

  
198
    sk_set_tbuf(ifa->sk, n->ldd_buffer);
192 199
    ospf_send_to(ifa, n->ip);
200
    sk_set_tbuf(ifa->sk, NULL);
193 201

  
194 202
    if(n->myimms.bit.ms) tm_start(n->rxmt_timer, n->ifa->rxmtint);		/* Restart timer */
195 203

  
......
262 270
  u32 ps_options = ntoh_opt(ps->options);
263 271
  u16 ps_iface_mtu = ntohs(ps->iface_mtu);
264 272
  
265
  OSPF_PACKET(ospf_dump_dbdes, ps, "DBDES packet received from %I via %s", n->ip, ifa->iface->name);
273
  OSPF_PACKET(ospf_dump_dbdes, ps, "DBDES packet received from %I via %s", n->ip, ifa->ifname);
266 274

  
267 275
  ospf_neigh_sm(n, INM_HELLOREC);
268 276

  
......
279 287
      return;
280 288
  case NEIGHBOR_EXSTART:
281 289

  
282
    if ((ps_iface_mtu != ifa->iface->mtu) && (ifa->type != OSPF_IT_VLINK)
290
    if ((ifa->type != OSPF_IT_VLINK) && (ps_iface_mtu != ifa->iface->mtu)
283 291
	&& (ps_iface_mtu != 0) && (ifa->iface->mtu != 0))
284 292
      log(L_WARN "OSPF: MTU mismatch with neighbour %I on interface %s (remote %d, local %d)",
285
	  n->ip, ifa->iface->name, ps_iface_mtu, ifa->iface->mtu);
293
	  n->ip, ifa->ifname, ps_iface_mtu, ifa->iface->mtu);
286 294

  
287 295
    if ((ps->imms.bit.m && ps->imms.bit.ms && ps->imms.bit.i)
288 296
	&& (n->rid > po->router_id) && (size == sizeof(struct ospf_dbdes_packet)))
......
361 369
    {
362 370
      if (ps_ddseq != n->dds)	/* MASTER */
363 371
      {
364
	OSPF_TRACE(D_PACKETS,
365
		   "dbdes - sequence mismatch neighbor %I (master)", n->ip);
372
	OSPF_TRACE(D_PACKETS, "dbdes - sequence mismatch neighbor %I (master)",
373
		   n->ip);
366 374
	ospf_neigh_sm(n, INM_SEQMIS);
367 375
	break;
368 376
      }
......
383 391
    {
384 392
      if (ps_ddseq != (n->dds + 1))	/* SLAVE */
385 393
      {
386
	OSPF_TRACE(D_PACKETS, "dbdes - sequence mismatch neighbor %I (slave)",
387
		   n->ip);
394
	OSPF_TRACE(D_PACKETS, "dbdes - sequence mismatch neighbor %I (slave)", n->ip);
388 395
	ospf_neigh_sm(n, INM_SEQMIS);
389 396
	break;
390 397
      }
proto/ospf/hello.c
61 61

  
62 62
  struct ospf_hello_packet *ps = (void *) ps_i;
63 63

  
64
  OSPF_TRACE(D_PACKETS, "HELLO packet received from %I via %s%s", faddr,
65
      (ifa->type == OSPF_IT_VLINK ? "vlink-" : ""), ifa->iface->name);
64
  OSPF_TRACE(D_PACKETS, "HELLO packet received from %I via %s", faddr, ifa->ifname);
66 65

  
67 66
#ifdef OSPFv2
68 67
  ip_addr mask = ps->netmask;
......
120 119

  
121 120
      if (!nn && ifa->strictnbma)
122 121
      {
123
	log(L_WARN "Ignoring new neighbor: %I on %s", faddr,
124
	    ifa->iface->name);
122
	log(L_WARN "Ignoring new neighbor: %I on %s", faddr, ifa->ifname);
125 123
	return;
126 124
      }
127 125

  
......
129 127
	  (((ps->priority == 0) && nn->eligible) ||
130 128
	   ((ps->priority > 0) && !nn->eligible)))
131 129
      {
132
	log(L_ERR "Eligibility mismatch for neighbor: %I on %s",
133
	    faddr, ifa->iface->name);
130
	log(L_ERR "Eligibility mismatch for neighbor: %I on %s", faddr, ifa->ifname);
134 131
	return;
135 132
      }
136 133

  
......
138 135
	nn->found = 1;
139 136
    }
140 137

  
141
    OSPF_TRACE(D_EVENTS, "New neighbor found: %I on %s", faddr,
142
	       ifa->iface->name);
138
    OSPF_TRACE(D_EVENTS, "New neighbor found: %I on %s", faddr, ifa->ifname);
143 139

  
144 140
    n = ospf_neighbor_new(ifa);
145 141

  
......
263 259

  
264 260
  p = (struct proto *) (ifa->oa->po);
265 261
  DBG("%s: Hello/Poll timer fired on interface %s with IP %I\n",
266
      p->name, ifa->iface->name, ifa->addr->ip);
262
      p->name, ifa->ifname, ifa->addr->ip);
267 263

  
268 264
  /* Now we should send a hello packet */
269 265
  pkt = ospf_tx_buffer(ifa);
......
309 305
    u32 *pp = (u32 *) (((u8 *) pkt) + sizeof(struct ospf_hello_packet));
310 306
    WALK_LIST(neigh, ifa->neigh_list)
311 307
    {
312
      if ((i+1) * sizeof(u32) + sizeof(struct ospf_hello_packet) > ospf_pkt_bufsize(ifa))
308
      if ((i+1) * sizeof(u32) + sizeof(struct ospf_hello_packet) > ospf_pkt_maxsize(ifa))
313 309
      {
314
	log(L_WARN "%s: Too many neighbors on interface %s", p->name, ifa->iface->name);
310
	log(L_WARN "%s: Too many neighbors on interface %s", p->name, ifa->ifname);
315 311
	break;
316 312
      }
317 313
      *(pp + i) = htonl(neigh->rid);
......
376 372
    bug("Bug in ospf_hello_send()");
377 373
  }
378 374

  
379
  OSPF_TRACE(D_PACKETS, "HELLO packet sent via %s%s",
380
	     (ifa->type == OSPF_IT_VLINK ? "vlink-" : ""), ifa->iface->name);
375
  OSPF_TRACE(D_PACKETS, "HELLO packet sent via %s", ifa->ifname);
381 376
}
proto/ospf/iface.c
36 36
  struct ospf_iface *ifa = (struct ospf_iface *) timer->data;
37 37
  struct proto *p = &ifa->oa->po->proto;
38 38

  
39
  OSPF_TRACE(D_EVENTS, "Wait timer fired on interface %s.", ifa->iface->name);
39
  OSPF_TRACE(D_EVENTS, "Wait timer fired on interface %s.", ifa->ifname);
40 40
  ospf_iface_sm(ifa, ISM_WAITF);
41 41
}
42 42

  
43
static void ospf_iface_change_mtu(struct proto_ospf *po, struct ospf_iface *ifa);
43
static inline uint
44
ifa_tx_length(struct ospf_iface *ifa)
45
{
46
  return ifa->cf->tx_length ?: ifa->iface->mtu; 
47
}
44 48

  
45
u32
46
rxbufsize(struct ospf_iface *ifa)
49
static inline uint
50
ifa_bufsize(struct ospf_iface *ifa)
47 51
{
48
  switch(ifa->rxbuf)
49
  {
50
    case OSPF_RXBUF_NORMAL:
51
      return (ifa->iface->mtu * 2);
52
      break;
53
    case OSPF_RXBUF_LARGE:
54
      return OSPF_MAX_PKT_SIZE;
55
      break;
56
    default:
57
      return ifa->rxbuf;
58
      break;
59
  }
52
  uint bsize = ifa->cf->rx_buffer ?: ifa->iface->mtu;
53
  return MAX(bsize, ifa->tx_length);
60 54
}
61 55

  
56
int
57
ospf_iface_assure_bufsize(struct ospf_iface *ifa, uint plen)
58
{
59
  plen += SIZE_OF_IP_HEADER;
60

  
61
#ifdef OSPFv2
62
  if (ifa->autype == OSPF_AUTH_CRYPT)
63
    plen += OSPF_AUTH_CRYPT_SIZE;
64
#endif
65

  
66
  if (plen <= ifa->sk->tbsize)
67
    return 0;
68

  
69
  if (ifa->cf->rx_buffer || (plen > 0xffff))
70
    return -1;
71

  
72
  plen = BIRD_ALIGN(plen, 1024);
73
  plen = MIN(plen, 0xffff);
74
  sk_set_tbsize(ifa->sk, plen);
75
  return 1;
76
}
77

  
78

  
62 79
struct nbma_node *
63 80
find_nbma_node_in(list *nnl, ip_addr ip)
64 81
{
......
69 86
  return NULL;
70 87
}
71 88

  
89

  
72 90
static int
73 91
ospf_sk_open(struct ospf_iface *ifa)
74 92
{
75 93
  sock *sk = sk_new(ifa->pool);
76 94
  sk->type = SK_IP;
77 95
  sk->dport = OSPF_PROTO;
78
  sk->saddr = IPA_NONE;
96
  sk->saddr = ifa->addr->ip;
97
  sk->iface = ifa->iface;
79 98

  
80 99
  sk->tos = ifa->cf->tx_tos;
81 100
  sk->priority = ifa->cf->tx_priority;
82 101
  sk->rx_hook = ospf_rx_hook;
83
  sk->tx_hook = ospf_tx_hook;
102
  // sk->tx_hook = ospf_tx_hook;
84 103
  sk->err_hook = ospf_err_hook;
85
  sk->iface = ifa->iface;
86
  sk->rbsize = rxbufsize(ifa);
87
  sk->tbsize = rxbufsize(ifa);
104
  sk->rbsize = sk->tbsize = ifa_bufsize(ifa);
88 105
  sk->data = (void *) ifa;
89 106
  sk->flags = SKF_LADDR_RX | (ifa->check_ttl ? SKF_TTL_RX : 0);
90
  sk->ttl = ifa->cf->ttl_security ? 255 : -1;
107
  sk->ttl = ifa->cf->ttl_security ? 255 : 1;
91 108

  
92
  if (sk_open(sk) != 0)
109
  if (sk_open(sk) < 0)
93 110
    goto err;
94 111

  
95 112
#ifdef OSPFv3
......
98 115
    goto err;
99 116
#endif
100 117

  
101
  /*
102
   * For OSPFv2: When sending a packet, it is important to have a
103
   * proper source address. We expect that when we send one-hop
104
   * unicast packets, OS chooses a source address according to the
105
   * destination address (to be in the same prefix). We also expect
106
   * that when we send multicast packets, OS uses the source address
107
   * from sk->saddr registered to OS by sk_setup_multicast(). This
108
   * behavior is needed to implement multiple virtual ifaces (struct
109
   * ospf_iface) on one physical iface and is signalized by
110
   * CONFIG_MC_PROPER_SRC.
111
   *
112
   * If this behavior is not available (for example on BSD), we create
113
   * non-stub iface just for the primary IP address (see
114
   * ospf_iface_stubby()) and we expect OS to use primary IP address
115
   * as a source address for both unicast and multicast packets.
116
   *
117
   * FIXME: the primary IP address is currently just the
118
   * lexicographically smallest address on an interface, it should be
119
   * signalized by sysdep code which one is really the primary.
120
   */
121

  
122
  sk->saddr = ifa->addr->ip;
123 118
  if ((ifa->type == OSPF_IT_BCAST) || (ifa->type == OSPF_IT_PTP))
124 119
  {
125 120
    if (ifa->cf->real_bcast)
......
132 127
    else
133 128
    {
134 129
      ifa->all_routers = AllSPFRouters;
135
      sk->ttl = ifa->cf->ttl_security ? 255 : 1;
136 130

  
137 131
      if (sk_setup_multicast(sk) < 0)
138 132
        goto err;
......
171 165
  ifa->sk_dr = 0;
172 166
}
173 167

  
168
void
169
ospf_open_vlink_sk(struct proto_ospf *po)
170
{
171
  struct proto *p = &po->proto;
172

  
173
  sock *sk = sk_new(po->proto.pool);
174
  sk->type = SK_IP;
175
  sk->dport = OSPF_PROTO;
176

  
177
  /* FIXME: configurable tos/priority ? */
178
  sk->tos = IP_PREC_INTERNET_CONTROL;
179
  sk->priority = sk_priority_control;
180
  sk->err_hook = ospf_verr_hook;
181

  
182
  sk->rbsize = 0;
183
  sk->tbsize = OSPF_VLINK_MTU;
184
  sk->data = (void *) po;
185
  sk->flags = 0;
186

  
187
  if (sk_open(sk) < 0)
188
    goto err;
189

  
190
#ifdef OSPFv3
191
  /* 12 is an offset of the checksum in an OSPF packet */
192
  if (sk_set_ipv6_checksum(sk, 12) < 0)
193
    goto err;
194
#endif
195

  
196
  po->vlink_sk = sk;
197
  return;
198

  
199
 err:
200
  rfree(sk);
201
  log(L_ERR "%s: Cannot open virtual link socket", p->name);
202
}
203

  
174 204
static void
175 205
ospf_iface_down(struct ospf_iface *ifa)
176 206
{
......
183 213
  {
184 214
#ifdef OSPFv2
185 215
    OSPF_TRACE(D_EVENTS, "Removing interface %s (%I/%d) from area %R",
186
	       ifa->iface->name, ifa->addr->prefix, ifa->addr->pxlen, ifa->oa->areaid);
216
	       ifa->ifname, ifa->addr->prefix, ifa->addr->pxlen, ifa->oa->areaid);
187 217
#else
188 218
    OSPF_TRACE(D_EVENTS, "Removing interface %s (IID %d) from area %R",
189
	       ifa->iface->name, ifa->instance_id, ifa->oa->areaid);
219
	       ifa->ifname, ifa->instance_id, ifa->oa->areaid);
190 220
#endif
191 221

  
192 222
    /* First of all kill all the related vlinks */
......
215 245
  if (ifa->type == OSPF_IT_VLINK)
216 246
  {
217 247
    ifa->vifa = NULL;
218
    ifa->iface = NULL;
219 248
    ifa->addr = NULL;
220
    ifa->sk = NULL;
221 249
    ifa->cost = 0;
222 250
    ifa->vip = IPA_NONE;
223 251
  }
......
276 304
	       ifa->vid, ospf_is[oldstate], ospf_is[state]);
277 305
  else
278 306
    OSPF_TRACE(D_EVENTS, "Changing state of iface %s from %s to %s",
279
	       ifa->iface->name, ospf_is[oldstate], ospf_is[state]);
307
	       ifa->ifname, ospf_is[oldstate], ospf_is[state]);
280 308

  
281 309
  if ((ifa->type == OSPF_IT_BCAST) && !ifa->cf->real_bcast && ifa->sk)
282 310
  {
......
318 346
void
319 347
ospf_iface_sm(struct ospf_iface *ifa, int event)
320 348
{
321
  DBG("SM on %s %s. Event is '%s'\n", (ifa->type == OSPF_IT_VLINK) ? "vlink" : "iface",
322
    ifa->iface ? ifa->iface->name : "(none)" , ospf_ism[event]);
349
  DBG("SM on iface %s. Event is '%s'\n", ifa->ifname, ospf_ism[event]);
323 350

  
324 351
  switch (event)
325 352
  {
......
436 463
  /* Open socket if interface is not stub */
437 464
  if (! ifa->stub && ! ospf_sk_open(ifa))
438 465
  {
439
    log(L_ERR "%s: Socket open failed on interface %s, declaring as stub", p->name, ifa->iface->name);
466
    log(L_ERR "%s: Socket open failed on interface %s, declaring as stub", p->name, ifa->ifname);
440 467
    ifa->ioprob = OSPF_I_SK;
441 468
    ifa->stub = 1;
442 469
  }
......
469 496
static int
470 497
ospf_iface_stubby(struct ospf_iface_patt *ip, struct ifa *addr)
471 498
{
472
  if (! addr)
473
    return 0;
474

  
475 499
  /* a host address */
476 500
  if (addr->flags & IA_HOST)
477 501
    return 1;
......
481 505
    return 1;
482 506

  
483 507
  /*
484
   * We cannot properly support multiple OSPF ifaces on real iface
485
   * with multiple prefixes, therefore we force OSPF ifaces with
486
   * non-primary IP prefixes to be stub.
508
   * For compatibility reasons on BSD systems, we force OSPF
509
   * interfaces with non-primary IP prefixes to be stub.
487 510
   */
488 511
#if defined(OSPFv2) && !defined(CONFIG_MC_PROPER_SRC)
489
  if (! (addr->flags & IA_PRIMARY))
512
  if (!ip->bsd_secondary && !(addr->flags & IA_PRIMARY))
490 513
    return 1;
491 514
#endif
492 515

  
......
497 520
ospf_iface_new(struct ospf_area *oa, struct ifa *addr, struct ospf_iface_patt *ip)
498 521
{
499 522
  struct proto *p = &oa->po->proto;
500
  struct iface *iface = addr ? addr->iface : NULL;
501
  struct pool *pool;
502

  
523
  struct iface *iface = addr->iface;
503 524
  struct ospf_iface *ifa;
504
  struct nbma_node *nb;
505
  struct object_lock *lock;
525
  struct pool *pool;
506 526

  
507
  if (ip->type == OSPF_IT_VLINK)
508
    OSPF_TRACE(D_EVENTS, "Adding vlink to %R via area %R", ip->vid, ip->voa);
509
  else
510
  {
511 527
#ifdef OSPFv2
512
    OSPF_TRACE(D_EVENTS, "Adding interface %s (%I/%d) to area %R",
513
	       iface->name, addr->prefix, addr->pxlen, oa->areaid);
528
  OSPF_TRACE(D_EVENTS, "Adding interface %s (%I/%d) to area %R",
529
	     iface->name, addr->prefix, addr->pxlen, oa->areaid);
514 530
#else
515
    OSPF_TRACE(D_EVENTS, "Adding interface %s (IID %d) to area %R",
516
	       iface->name, ip->instance_id, oa->areaid);
531
  OSPF_TRACE(D_EVENTS, "Adding interface %s (IID %d) to area %R",
532
	     iface->name, ip->instance_id, oa->areaid);
517 533
#endif
518
  }
519 534

  
520 535
  pool = rp_new(p->pool, "OSPF Interface");
521 536
  ifa = mb_allocz(pool, sizeof(struct ospf_iface));
......
525 540
  ifa->cf = ip;
526 541
  ifa->pool = pool;
527 542

  
543
  ifa->iface_id = iface->index;
544
  ifa->ifname = iface->name;
545

  
528 546
  ifa->cost = ip->cost;
529 547
  ifa->rxmtint = ip->rxmtint;
530 548
  ifa->inftransdelay = ip->inftransdelay;
......
536 554
  ifa->deadint = ip->deadint;
537 555
  ifa->stub = ospf_iface_stubby(ip, addr);
538 556
  ifa->ioprob = OSPF_I_OK;
539
  ifa->rxbuf = ip->rxbuf;
557

  
558
  ifa->tx_length = ifa_tx_length(ifa);
540 559
  ifa->check_link = ip->check_link;
541 560
  ifa->ecmp_weight = ip->ecmp_weight;
542 561
  ifa->check_ttl = (ip->ttl_security == 1);
......
545 564
#ifdef OSPFv2
546 565
  ifa->autype = ip->autype;
547 566
  ifa->passwords = ip->passwords;
548
  ifa->ptp_netmask = addr ? !(addr->flags & IA_PEER) : 0;
567
  ifa->ptp_netmask = !(addr->flags & IA_PEER);
549 568
  if (ip->ptp_netmask < 2)
550 569
    ifa->ptp_netmask = ip->ptp_netmask;
551 570
#endif
......
554 573
  ifa->instance_id = ip->instance_id;
555 574
#endif
556 575

  
576

  
557 577
  ifa->type = ospf_iface_classify(ip->type, addr);
558 578

  
559 579
  /* Check validity of interface type */
......
578 598
    log(L_WARN "%s: Cannot use interface %s as %s, forcing %s",
579 599
	p->name, iface->name, ospf_it[old_type], ospf_it[ifa->type]);
580 600

  
581
  /* Assign iface ID, for vlinks, this is ugly hack */
582
  ifa->iface_id = (ifa->type != OSPF_IT_VLINK) ? iface->index : oa->po->last_vlink_id++;
583 601

  
602
  ifa->state = OSPF_IS_DOWN;
584 603
  init_list(&ifa->neigh_list);
585 604
  init_list(&ifa->nbma_list);
586 605

  
606
  struct nbma_node *nb;
587 607
  WALK_LIST(nb, ip->nbma_list)
588 608
  {
589 609
    /* In OSPFv3, addr is link-local while configured neighbors could
......
602 622
    add_nbma_node(ifa, nb, 0);
603 623
  }
604 624

  
605
  ifa->state = OSPF_IS_DOWN;
606 625
  add_tail(&oa->po->iface_list, NODE ifa);
607 626

  
608
  if (ifa->type == OSPF_IT_VLINK)
609
  {
610
    ifa->voa = ospf_find_area(oa->po, ip->voa);
611
    ifa->vid = ip->vid;
612

  
613
    ifa->hello_timer = tm_new_set(ifa->pool, hello_timer_hook, ifa, 0, ifa->helloint);
614

  
615
    return;			/* Don't lock, don't add sockets */
616
  }
617

  
618 627
  /*
619 628
   * In some cases we allow more ospf_ifaces on one physical iface.
620 629
   * In OSPFv2, if they use different IP address prefix.
......
622 631
   * Therefore, we store such info to lock->addr field.
623 632
   */
624 633

  
625
  lock = olock_new(pool);
634
  struct object_lock *lock = olock_new(pool);
626 635
#ifdef OSPFv2
627 636
  lock->addr = ifa->addr->prefix;
628 637
#else /* OSPFv3 */
......
637 646
  olock_acquire(lock);
638 647
}
639 648

  
649
void
650
ospf_iface_new_vlink(struct proto_ospf *po, struct ospf_iface_patt *ip)
651
{
652
  struct proto *p = &po->proto;
653
  struct ospf_iface *ifa;
654
  struct pool *pool;
655

  
656
  if (!po->vlink_sk)
657
    return;
658

  
659
  OSPF_TRACE(D_EVENTS, "Adding vlink to %R via area %R", ip->vid, ip->voa);
660

  
661
  /* Vlink ifname is stored just after the ospf_iface structure */
662

  
663
  pool = rp_new(p->pool, "OSPF Vlink");
664
  ifa = mb_allocz(pool, sizeof(struct ospf_iface) + 16);
665
  ifa->oa = po->backbone;
666
  ifa->cf = ip;
667
  ifa->pool = pool;
668

  
669
  /* Assign iface ID, for vlinks, this is ugly hack */
670
  u32 vlink_id = po->last_vlink_id++;
671
  ifa->iface_id = vlink_id + OSPF_VLINK_ID_OFFSET;
672
  ifa->ifname = (void *) (ifa + 1);
673
  bsprintf(ifa->ifname, "vlink%d", vlink_id);
674

  
675
  ifa->voa = ospf_find_area(po, ip->voa);
676
  ifa->vid = ip->vid;
677
  ifa->sk = po->vlink_sk;
678

  
679
  ifa->helloint = ip->helloint;
680
  ifa->rxmtint = ip->rxmtint;
681
  ifa->waitint = ip->waitint;
682
  ifa->deadint = ip->deadint;
683
  ifa->inftransdelay = ip->inftransdelay;
684
  ifa->tx_length = OSPF_VLINK_MTU;
685

  
686
#ifdef OSPFv2
687
  ifa->autype = ip->autype;
688
  ifa->passwords = ip->passwords;
689
#endif
690

  
691
#ifdef OSPFv3
692
  ifa->instance_id = ip->instance_id;
693
#endif
694

  
695
  ifa->type = OSPF_IT_VLINK;
696

  
697
  ifa->state = OSPF_IS_DOWN;
698
  init_list(&ifa->neigh_list);
699
  init_list(&ifa->nbma_list);
700

  
701
  add_tail(&po->iface_list, NODE ifa);
702

  
703
  ifa->hello_timer = tm_new_set(ifa->pool, hello_timer_hook, ifa, 0, ifa->helloint);
704
}
705

  
640 706
static void
641 707
ospf_iface_change_timer(timer *tm, unsigned val)
642 708
{
......
653 719
ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new)
654 720
{
655 721
  struct proto *p = &ifa->oa->po->proto;
656
  struct nbma_node *nb, *nbx;
657
  char *ifname = (ifa->type != OSPF_IT_VLINK) ? ifa->iface->name : "vlink";
722
  struct ospf_iface_patt *old = ifa->cf;
723
  char *ifname = ifa->ifname;
658 724

  
659 725
  /* Type could be changed in ospf_iface_new(),
660 726
     but if config values are same then also results are same */
661
  int old_type = ospf_iface_classify(ifa->cf->type, ifa->addr);
727
  int old_type = ospf_iface_classify(old->type, ifa->addr);
662 728
  int new_type = ospf_iface_classify(new->type, ifa->addr);
663 729
  if (old_type != new_type)
664 730
    return 0;
......
668 734
    return 0;
669 735

  
670 736
  /* Change of these options would require to reset the iface socket */
671
  if ((new->real_bcast != ifa->cf->real_bcast) ||
672
      (new->tx_tos != ifa->cf->tx_tos) ||
673
      (new->tx_priority != ifa->cf->tx_priority) ||
674
      (new->ttl_security != ifa->cf->ttl_security))
737
  if ((new->real_bcast != old->real_bcast) ||
738
      (new->tx_tos != old->tx_tos) ||
739
      (new->tx_priority != old->tx_priority) ||
740
      (new->ttl_security != old->ttl_security))
675 741
    return 0;
676 742

  
677 743
  ifa->cf = new;
......
775 841
    ifa->strictnbma = new->strictnbma;
776 842
  }
777 843

  
844
  struct nbma_node *nb, *nbx;
845

  
778 846
  /* NBMA LIST - remove or update old */
779 847
  WALK_LIST_DELSAFE(nb, nbx, ifa->nbma_list)
780 848
  {
......
817 885
    }
818 886
  }
819 887

  
820
  /* RX BUFF */
821
  if (ifa->rxbuf != new->rxbuf)
888
  int update_buffers = 0;
889

  
890
  /* TX LENGTH */
891
  if (old->tx_length != new->tx_length)
892
  {
893
    OSPF_TRACE(D_EVENTS, "Changing TX length on interface %s from %d to %d",
894
	       ifname, old->tx_length, new->tx_length);
895

  
896
    /* ifa cannot be vlink */
897
    ifa->tx_length = ifa_tx_length(ifa);
898
    update_buffers = 1;
899
  }
900

  
901
  /* RX BUFFER */
902
  if (old->rx_buffer != new->rx_buffer)
903
  {
904
    OSPF_TRACE(D_EVENTS, "Changing buffer size on interface %s from %d to %d",
905
	       ifname, old->rx_buffer, new->rx_buffer);
906

  
907
    /* ifa cannot be vlink */
908
    update_buffers = 1;
909
  }
910

  
911
  /* Buffer size depends on both tx_length and rx_buffer options */
912
  if (update_buffers && ifa->sk)
822 913
  {
823
    OSPF_TRACE(D_EVENTS, "Changing rxbuf interface %s from %d to %d",
824
	       ifname, ifa->rxbuf, new->rxbuf);
825
    ifa->rxbuf = new->rxbuf;
826
    ospf_iface_change_mtu(ifa->oa->po, ifa);
914
    uint bsize = ifa_bufsize(ifa);
915
    sk_set_rbsize(ifa->sk, bsize);
916
    sk_set_tbsize(ifa->sk, bsize);
827 917
  }
828 918

  
829 919
  /* LINK */
......
833 923
	       new->check_link ? "Enabling" : "Disabling", ifname);
834 924
    ifa->check_link = new->check_link;
835 925

  
926
    /* ifa cannot be vlink */
836 927
    if (!(ifa->iface->flags & IF_LINK_UP))
837 928
      ospf_iface_sm(ifa, ifa->check_link ? ISM_LOOP : ISM_UNLOOP);
838 929
  }
......
929 1020
void
930 1021
ospf_ifaces_reconfigure(struct ospf_area *oa, struct ospf_area_config *nac)
931 1022
{
1023
  struct proto *p = &oa->po->proto;
932 1024
  struct ospf_iface_patt *ip;
933 1025
  struct iface *iface;
934 1026
  struct ifa *a;
......
956 1048
	    continue;
957 1049

  
958 1050
	  /* Hard restart */
1051
	  log(L_INFO "%s: Restarting interface %s (%I/%d) in area %R",
1052
	      p->name, ifa->ifname, a->prefix, a->pxlen, oa->areaid);
959 1053
	  ospf_iface_shutdown(ifa);
960 1054
	  ospf_iface_remove(ifa);
961 1055
	}
......
1062 1156
void
1063 1157
ospf_ifaces_reconfigure(struct ospf_area *oa, struct ospf_area_config *nac)
1064 1158
{
1159
  struct proto *p = &oa->po->proto;
1065 1160
  struct ospf_iface_patt *ip;
1066 1161
  struct iface *iface;
1067 1162
  struct ifa *a;
......
1092 1187
	    continue;
1093 1188

  
1094 1189
	  /* Hard restart */
1190
	  log(L_INFO "%s: Restarting interface %s (IID %d) in area %R",
1191
	      p->name, ifa->ifname, ifa->instance_id, oa->areaid);
1095 1192
	  ospf_iface_shutdown(ifa);
1096 1193
	  ospf_iface_remove(ifa);
1097 1194
	}
......
1108 1205
ospf_iface_change_mtu(struct proto_ospf *po, struct ospf_iface *ifa)
1109 1206
{
1110 1207
  struct proto *p = &po->proto;
1111
  struct ospf_packet *op;
1112
  struct ospf_neighbor *n;
1113
  OSPF_TRACE(D_EVENTS, "Changing MTU on interface %s", ifa->iface->name);
1114 1208

  
1115
  if (ifa->sk)
1116
  {
1117
    ifa->sk->rbsize = rxbufsize(ifa);
1118
    ifa->sk->tbsize = rxbufsize(ifa);
1119
    sk_reallocate(ifa->sk);
1120
  }
1209
  /* ifa is not vlink */
1121 1210

  
1122
  WALK_LIST(n, ifa->neigh_list)
1123
  {
1124
    op = (struct ospf_packet *) n->ldbdes;
1125
    n->ldbdes = mb_allocz(n->pool, ifa->iface->mtu);
1211
  OSPF_TRACE(D_EVENTS, "Changing MTU on interface %s", ifa->ifname);
1126 1212

  
1127
    if (ntohs(op->length) <= ifa->iface->mtu)	/* If the packet in old buffer is bigger, let it filled by zeros */
1128
      memcpy(n->ldbdes, op, ifa->iface->mtu);	/* If the packet is old is same or smaller, copy it */
1213
  ifa->tx_length = ifa_tx_length(ifa);
1129 1214

  
1130
    mb_free(op);
1131
  }
1215
  if (!ifa->sk)
1216
    return;
1217

  
1218
  /* We do not shrink dynamic buffers */
1219
  uint bsize = ifa_bufsize(ifa);
1220
  if (bsize > ifa->sk->rbsize)
1221
    sk_set_rbsize(ifa->sk, bsize);
1222
  if (bsize > ifa->sk->tbsize)
1223
    sk_set_tbsize(ifa->sk, bsize);
1132 1224
}
1133 1225

  
1134 1226
static void
1135 1227
ospf_iface_notify(struct proto_ospf *po, unsigned flags, struct ospf_iface *ifa)
1136 1228
{
1229
  /* ifa is not vlink */
1230

  
1137 1231
  if (flags & IF_CHANGE_DOWN)
1138 1232
  {
1139 1233
    ospf_iface_remove(ifa);
......
1163 1257

  
1164 1258
  struct ospf_iface *ifa, *ifx;
1165 1259
  WALK_LIST_DELSAFE(ifa, ifx, po->iface_list)
1166
    if ((ifa->type != OSPF_IT_VLINK) && (ifa->iface == iface))
1260
    if (ifa->iface == iface)
1167 1261
      ospf_iface_notify(po, flags, ifa);
1168 1262

  
1169 1263
  /* We use here that even shutting down iface also shuts down
......
1186 1280

  
1187 1281
  if (ifa->type == OSPF_IT_VLINK)
1188 1282
  {
1189
    cli_msg(-1015, "Virtual link to %R:", ifa->vid);
1283
    cli_msg(-1015, "Virtual link %s to %R:", ifa->ifname, ifa->vid);
1190 1284
    cli_msg(-1015, "\tPeer IP: %I", ifa->vip);
1191
    cli_msg(-1015, "\tTransit area: %R (%u)", ifa->voa->areaid,
1192
	    ifa->voa->areaid);
1193
    cli_msg(-1015, "\tInterface: \"%s\"",
1194
	    (ifa->iface ? ifa->iface->name : "(none)"));
1285
    cli_msg(-1015, "\tTransit area: %R (%u)", ifa->voa->areaid, ifa->voa->areaid);
1195 1286
  }
1196 1287
  else
1197 1288
  {
1198 1289
#ifdef OSPFv2
1199 1290
    if (ifa->addr->flags & IA_PEER)
1200
      cli_msg(-1015, "Interface %s (peer %I)", ifa->iface->name, ifa->addr->opposite);
1291
      cli_msg(-1015, "Interface %s (peer %I)", ifa->ifname, ifa->addr->opposite);
1201 1292
    else
1202
      cli_msg(-1015, "Interface %s (%I/%d)", ifa->iface->name, ifa->addr->prefix, ifa->addr->pxlen);
1293
      cli_msg(-1015, "Interface %s (%I/%d)", ifa->ifname, ifa->addr->prefix, ifa->addr->pxlen);
1203 1294
#else /* OSPFv3 */
1204
    cli_msg(-1015, "Interface %s (IID %d)", ifa->iface->name, ifa->instance_id);
1295
    cli_msg(-1015, "Interface %s (IID %d)", ifa->ifname, ifa->instance_id);
1205 1296
#endif
1206 1297
    cli_msg(-1015, "\tType: %s%s", ospf_it[ifa->type], more);
1207 1298
    cli_msg(-1015, "\tArea: %R (%u)", ifa->oa->areaid, ifa->oa->areaid);
proto/ospf/iface.h
17 17
void ospf_ifa_notify(struct proto *p, unsigned flags, struct ifa *a);
18 18
void ospf_iface_info(struct ospf_iface *ifa);
19 19
void ospf_iface_new(struct ospf_area *oa, struct ifa *addr, struct ospf_iface_patt *ip);
20
void ospf_iface_new_vlink(struct proto_ospf *po, struct ospf_iface_patt *ip);
20 21
void ospf_iface_remove(struct ospf_iface *ifa);
21 22
void ospf_iface_shutdown(struct ospf_iface *ifa);
22 23
int ospf_iface_reconfigure(struct ospf_iface *ifa, struct ospf_iface_patt *new);
23 24
void ospf_ifaces_reconfigure(struct ospf_area *oa, struct ospf_area_config *nac);
24 25

  
26
int ospf_iface_assure_bufsize(struct ospf_iface *ifa, uint plen);
27

  
28
void ospf_open_vlink_sk(struct proto_ospf *po);
29

  
25 30
struct nbma_node *find_nbma_node_in(list *nnl, ip_addr ip);
26 31

  
27 32
static inline struct nbma_node *
proto/ospf/lsack.c
92 92
	op->length = htons(len);
93 93
	DBG("Sending and continuing! Len=%u\n", len);
94 94

  
95
	OSPF_PACKET(ospf_dump_lsack, pk, "LSACK packet sent via %s", ifa->iface->name);
95
	OSPF_PACKET(ospf_dump_lsack, pk, "LSACK packet sent via %s", ifa->ifname);
96 96

  
97 97
	if (ifa->type == OSPF_IT_BCAST)
98 98
	{
......
121 121
  op->length = htons(len);
122 122
  DBG("Sending! Len=%u\n", len);
123 123

  
124
  OSPF_PACKET(ospf_dump_lsack, pk, "LSACK packet sent via %s", ifa->iface->name);
124
  OSPF_PACKET(ospf_dump_lsack, pk, "LSACK packet sent via %s", ifa->ifname);
125 125

  
126 126
  if (ifa->type == OSPF_IT_BCAST)
127 127
  {
......
153 153
  }
154 154

  
155 155
  struct ospf_lsack_packet *ps = (void *) ps_i;
156
  OSPF_PACKET(ospf_dump_lsack, ps, "LSACK packet received from %I via %s", n->ip, ifa->iface->name);
156
  OSPF_PACKET(ospf_dump_lsack, ps, "LSACK packet received from %I via %s", n->ip, ifa->ifname);
157 157

  
158 158
  ospf_neigh_sm(n, INM_HELLOREC);
159 159

  
proto/ospf/lsreq.c
82 82
					i) * sizeof(struct ospf_lsreq_header);
83 83
  op->length = htons(length);
84 84

  
85
  OSPF_PACKET(ospf_dump_lsreq, pk, "LSREQ packet sent to %I via %s", n->ip, n->ifa->iface->name);
85
  OSPF_PACKET(ospf_dump_lsreq, pk, "LSREQ packet sent to %I via %s", n->ip, n->ifa->ifname);
86 86
  ospf_send_to(n->ifa, n->ip);
87 87
}
88 88

  
......
107 107
  }
108 108

  
109 109
  struct ospf_lsreq_packet *ps = (void *) ps_i;
110
  OSPF_PACKET(ospf_dump_lsreq, ps, "LSREQ packet received from %I via %s", n->ip, ifa->iface->name);
110
  OSPF_PACKET(ospf_dump_lsreq, ps, "LSREQ packet received from %I via %s", n->ip, ifa->ifname);
111 111

  
112 112
  if (n->state < NEIGHBOR_EXCHANGE)
113 113
    return;
proto/ospf/lsupd.c
278 278
      struct ospf_packet *op;
279 279
      struct ospf_lsa_header *lh;
280 280

  
281
      pk = ospf_tx_buffer(ifa);
282
      op = &pk->ospf_packet;
283

  
284
      ospf_pkt_fill_hdr(ifa, pk, LSUPD_P);
285
      pk->lsano = htonl(1);
286

  
287 281
      /* Check iface buffer size */
288
      int len2 = sizeof(struct ospf_lsupd_packet) + (hn ? ntohs(hn->length) : hh->length);
289
      if (len2 > ospf_pkt_bufsize(ifa))
282
      uint len2 = sizeof(struct ospf_lsupd_packet) + (hn ? ntohs(hn->length) : hh->length);
283
      if (ospf_iface_assure_bufsize(ifa, len2) < 0)
290 284
      {
291 285
	/* Cannot fit in a tx buffer, skip that iface */
292 286
	log(L_ERR "OSPF: LSA too large to flood on %s (Type: %04x, Id: %R, Rt: %R)", 
293
	    ifa->iface->name, hh->type, hh->id, hh->rt);
287
	    ifa->ifname, hh->type, hh->id, hh->rt);
294 288
	continue;
295 289
      }
296 290

  
291
      pk = ospf_tx_buffer(ifa);
292
      op = &pk->ospf_packet;
293

  
294
      ospf_pkt_fill_hdr(ifa, pk, LSUPD_P);
295
      pk->lsano = htonl(1);
296

  
297 297
      lh = (struct ospf_lsa_header *) (pk + 1);
298 298

  
299 299
      /* Copy LSA into the packet */
......
322 322

  
323 323
      op->length = htons(len);
324 324

  
325
      OSPF_PACKET(ospf_dump_lsupd, pk, "LSUPD packet flooded via %s", ifa->iface->name);
325
      OSPF_PACKET(ospf_dump_lsupd, pk, "LSUPD packet flooded via %s", ifa->ifname);
326 326

  
327 327
      switch (ifa->type)
328 328
      {
......
406 406
	  break;
407 407

  
408 408
	/* LSA is larger than MTU, check buffer size */
409
	if (len2 > ospf_pkt_bufsize(n->ifa))
409
	if (ospf_iface_assure_bufsize(n->ifa, len2) < 0)
410 410
	{
411 411
	  /* Cannot fit in a tx buffer, skip that */
412 412
	  log(L_ERR "OSPF: LSA too large to send (Type: %04x, Id: %R, Rt: %R)", 
......
414 414
	  lsr = NODE_NEXT(lsr);
415 415
	  continue;
416 416
	}
417

  
418
	/* TX buffer could be reallocated */
419
	pkt = ospf_tx_buffer(n->ifa);
420
	buf = (void *) pkt;
417 421
      }
418 422

  
419 423
      /* Copy the LSA to the packet */
......
432 436
    pkt->lsano = htonl(lsano);
433 437
    pkt->ospf_packet.length = htons(len);
434 438
    OSPF_PACKET(ospf_dump_lsupd, pkt, "LSUPD packet sent to %I via %s",
435
		n->ip, n->ifa->iface->name);
439
		n->ip, n->ifa->ifname);
436 440
    ospf_send_to(n->ifa, n->ip);
437 441
  }
438 442
}
......
455 459
  }
456 460

  
457 461
  struct ospf_lsupd_packet *ps = (void *) ps_i;
458
  OSPF_PACKET(ospf_dump_lsupd, ps, "LSUPD packet received from %I via %s", n->ip, ifa->iface->name);
462
  OSPF_PACKET(ospf_dump_lsupd, ps, "LSUPD packet received from %I via %s", n->ip, ifa->ifname);
459 463

  
460 464
  if (n->state < NEIGHBOR_EXCHANGE)
461 465
  {
proto/ospf/neighbor.c
69 69
  add_tail(&ifa->neigh_list, NODE n);
70 70
  n->adj = 0;
71 71
  n->csn = 0;
72
  n->ldbdes = mb_allocz(pool, ifa->iface->mtu);
73 72
  n->state = NEIGHBOR_DOWN;
74 73

  
75 74
  init_lists(n);
......
286 285
    {
287 286
    case OSPF_IS_DOWN:
288 287
    case OSPF_IS_LOOP:
289
      bug("%s: Iface %s in down state?", p->name, ifa->iface->name);
288
      bug("%s: Iface %s in down state?", p->name, ifa->ifname);
290 289
      break;
291 290
    case OSPF_IS_WAITING:
292
      DBG("%s: Neighbor? on iface %s\n", p->name, ifa->iface->name);
291
      DBG("%s: Neighbor? on iface %s\n", p->name, ifa->ifname);
293 292
      break;
294 293
    case OSPF_IS_DROTHER:
295 294
      if (((n->rid == ifa->drid) || (n->rid == ifa->bdrid))
......
303 302
	i = 1;
304 303
      break;
305 304
    default:
306
      bug("%s: Iface %s in unknown state?", p->name, ifa->iface->name);
305
      bug("%s: Iface %s in unknown state?", p->name, ifa->ifname);
307 306
      break;
308 307
    }
309 308
    break;
310 309
  default:
311
    bug("%s: Iface %s is unknown type?", p->name, ifa->iface->name);
310
    bug("%s: Iface %s is unknown type?", p->name, ifa->ifname);
312 311
    break;
313 312
  }
314
  DBG("%s: Iface %s can_do_adj=%d\n", p->name, ifa->iface->name, i);
313
  DBG("%s: Iface %s can_do_adj=%d\n", p->name, ifa->ifname, i);
315 314
  return i;
316 315
}
317 316

  
......
556 555
  struct ospf_iface *ifa = n->ifa;
557 556
  struct proto *p = &ifa->oa->po->proto;
558 557

  
559
  OSPF_TRACE(D_EVENTS,
560
	     "Inactivity timer fired on interface %s for neighbor %I.",
561
	     ifa->iface->name, n->ip);
558
  OSPF_TRACE(D_EVENTS, "Inactivity timer fired on interface %s for neighbor %I.",
559
	     ifa->ifname, n->ip);
562 560
  ospf_neigh_remove(n);
563 561
}
564 562

  
......
591 589
  if (req->down)
592 590
  {
593 591
    OSPF_TRACE(D_EVENTS, "BFD session down for %I on %s",
594
	       n->ip, n->ifa->iface->name);
592
	       n->ip, n->ifa->ifname);
595 593

  
596 594
    ospf_neigh_remove(n);
597 595
  }
......
641 639
    pos = "ptp  ";
642 640

  
643 641
  cli_msg(-1013, "%-1R\t%3u\t%s/%s\t%-5s\t%-10s %-1I", n->rid, n->priority,
644
	  ospf_ns[n->state], pos, etime,
645
          (ifa->type == OSPF_IT_VLINK ? "vlink" : ifa->iface->name), n->ip);
642
	  ospf_ns[n->state], pos, etime, ifa->ifname, n->ip);
646 643
}
647 644

  
648 645
static void
......
653 650
  struct top_hash_entry *en;
654 651

  
655 652
  DBG("%s: RXMT timer fired on interface %s for neigh: %I.\n",
656
      p->name, n->ifa->iface->name, n->ip);
653
      p->name, n->ifa->ifname, n->ip);
657 654

  
658 655
  if(n->state < NEIGHBOR_EXSTART) return;
659 656

  
proto/ospf/ospf.c
232 232
  struct ospf_area_config *ac;
233 233

  
234 234
  po->router_id = proto_get_router_id(p->cf);
235
  po->last_vlink_id = 0x80000000;
236 235
  po->rfc1583 = c->rfc1583;
237 236
  po->stub_router = c->stub_router;
238 237
  po->ebit = 0;
......
258 257
  WALK_LIST(ac, c->area_list)
259 258
    ospf_area_add(po, ac, 0);
260 259

  
260
  if (c->abr)
261
    ospf_open_vlink_sk(po);
262

  
261 263
  /* Add all virtual links */
262 264
  struct ospf_iface_patt *ic;
263 265
  WALK_LIST(ic, c->vlink_list)
264
    ospf_iface_new(po->backbone, NULL, ic);
266
    ospf_iface_new_vlink(po, ic);
265 267

  
266 268
  return PS_UP;
267 269
}
......
277 279

  
278 280
  WALK_LIST(ifa, po->iface_list)
279 281
  {
280
    OSPF_TRACE(D_EVENTS, "Interface: %s", (ifa->iface ? ifa->iface->name : "(null)"));
282
    OSPF_TRACE(D_EVENTS, "Interface: %s", ifa->ifname);
281 283
    OSPF_TRACE(D_EVENTS, "state: %u", ifa->state);
282 284
    OSPF_TRACE(D_EVENTS, "DR:  %R", ifa->drid);
283 285
    OSPF_TRACE(D_EVENTS, "BDR: %R", ifa->bdrid);
......
381 383
{
382 384
  struct proto *p = &ifa->oa->po->proto;
383 385

  
384
  OSPF_TRACE(D_EVENTS, "Scheduling network-LSA origination for iface %s", ifa->iface->name);
386
  OSPF_TRACE(D_EVENTS, "Scheduling network-LSA origination for iface %s", ifa->ifname);
385 387
  ifa->orignet = 1;
386 388
}
387 389

  
......
391 393
{
392 394
  struct proto *p = &ifa->oa->po->proto;
393 395

  
394
  OSPF_TRACE(D_EVENTS, "Scheduling link-LSA origination for iface %s", ifa->iface->name);
396
  OSPF_TRACE(D_EVENTS, "Scheduling link-LSA origination for iface %s", ifa->ifname);
395 397
  ifa->origlink = 1;
396 398
}
397 399
#endif
......
631 633
{
632 634
  char *type = "<bug>";
633 635

  
634
  switch(rte->attrs->source)
636
  switch (rte->attrs->source)
635 637
  {
636 638
    case RTS_OSPF:
637 639
      type = "I";
......
769 771
    if (ifa)
770 772
      ospf_iface_reconfigure(ifa, ip);
771 773
    else
772
      ospf_iface_new(po->backbone, NULL, ip);
774
      ospf_iface_new_vlink(po, ip);
773 775
  }
774 776

  
775 777
  /* Delete remaining ifaces and areas */
......
808 810
  cli_msg(-1013, "%-12s\t%3s\t%-15s\t%-5s\t%-10s %-12s", "Router ID", "Pri",
809 811
	  "     State", "DTime", "Interface", "Router IP");
810 812
  WALK_LIST(ifa, po->iface_list)
811
    if ((iff == NULL) || patmatch(iff, ifa->iface->name))
813
    if ((iff == NULL) || patmatch(iff, ifa->ifname))
812 814
      WALK_LIST(n, ifa->neigh_list)
813 815
	ospf_sh_neigh_info(n);
814 816
  cli_msg(0, "");
......
917 919

  
918 920
  cli_msg(-1015, "%s:", p->name);
919 921
  WALK_LIST(ifa, po->iface_list)
920
    if ((iff == NULL) || patmatch(iff, ifa->iface->name))
922
    if ((iff == NULL) || patmatch(iff, ifa->ifname))
921 923
      ospf_iface_info(ifa);
922 924
  cli_msg(0, "");
923 925
}
proto/ospf/ospf.h
10 10
#define _BIRD_OSPF_H_
11 11

  
12 12
#define MAXNETS 10
13
#define OSPF_MIN_PKT_SIZE 256
13 14
#define OSPF_MAX_PKT_SIZE 65535
14
/*
15
 * RFC 2328 says, maximum packet size is 65535 (IP packet size
16
 * limit). Really a bit less for OSPF, because this contains also IP
17
 * header. This could be too much for small systems, so I normally
18
 * allocate 2*mtu (i found one cisco sending packets mtu+16). OSPF
19
 * packets are almost always sent small enough to not be fragmented.
20
 */
21 15

  
22 16
#ifdef LOCAL_DEBUG
23 17
#define OSPF_FORCE_DEBUG 1
......
78 72
#define DEFAULT_ECMP_LIMIT 16
79 73
#define DEFAULT_TRANSINT 40
80 74

  
75
#define OSPF_VLINK_ID_OFFSET 0x80000000
76

  
81 77

  
82 78
struct ospf_config
83 79
{
......
179 175
struct ospf_iface
180 176
{
181 177
  node n;
182
  struct iface *iface;		/* Nest's iface, non-NULL (unless type OSPF_IT_VLINK) */
178
  struct iface *iface;		/* Nest's iface (NULL for vlinks) */
183 179
  struct ifa *addr;		/* IP prefix associated with that OSPF iface */
184 180
  struct ospf_area *oa;
185 181
  struct ospf_iface_patt *cf;
182
  char *ifname;			/* Interface name (iface->name), new one for vlinks */
183

  
186 184
  pool *pool;
187
  sock *sk;			/* IP socket (for DD ...) */
185
  sock *sk;			/* IP socket */
188 186
  list neigh_list;		/* List of neigbours */
189 187
  u32 cost;			/* Cost of iface */
190 188
  u32 waitint;			/* number of sec before changing state from wait */
......
273 271
  u8 sk_dr; 			/* Socket is a member of DRouters group */
274 272
  u8 marked;			/* Used in OSPF reconfigure */
275 273
  u16 rxbuf;			/* Buffer size */
274
  u16 tx_length;		/* Soft TX packet length limit, usually MTU */
276 275
  u8 check_link;		/* Whether iface link change is used */
277 276
  u8 ecmp_weight;		/* Weight used for ECMP */
278 277
  u8 ptp_netmask;		/* Send real netmask for P2P */
......
704 703
  slist lsrtl;			/* Link state retransmission list */
705 704
  siterator lsrti;
706 705
  struct top_graph *lsrth;
707
  void *ldbdes;			/* Last database description packet */
708 706
  timer *rxmt_timer;		/* RXMT timer */
709 707
  list ackl[2];
710 708
#define ACKL_DIRECT 0
711 709
#define ACKL_DELAY 1
712 710
  timer *ackd_timer;		/* Delayed ack timer */
713 711
  struct bfd_request *bfd_req;	/* BFD request, if BFD is used */
712
  void *ldd_buffer;		/* Last database description packet */
713
  u32 ldd_bsize;		/* Buffer size for ldd_buffer */
714 714
  u32 csn;                      /* Last received crypt seq number (for MD5) */
715 715
};
716 716

  
......
783 783
  void *lsab;			/* LSA buffer used when originating router LSAs */
784 784
  int lsab_size, lsab_used;
785 785
  linpool *nhpool;		/* Linpool used for next hops computed in SPF */
786
  sock *vlink_sk;		/* IP socket used for vlink TX */
786 787
  u32 router_id;
787 788
  u32 last_vlink_id;		/* Interface IDs for vlinks (starts at 0x80000000) */
788 789
};
......
806 807
  u32 vid;
807 808
  int tx_tos;
808 809
  int tx_priority;
809
  u16 rxbuf;
810
#define OSPF_RXBUF_NORMAL 0
811
#define OSPF_RXBUF_LARGE 1
810
  u16 tx_length;
811
  u16 rx_buffer;
812

  
812 813
#define OSPF_RXBUF_MINSIZE 256	/* Minimal allowed size */
813 814
  u16 autype;			/* Not really used in OSPFv3 */
814 815
#define OSPF_AUTH_NONE 0
......
822 823
  u8 ptp_netmask;		/* bool + 2 for unspecified */
823 824
  u8 ttl_security;		/* bool + 2 for TX only */
824 825
  u8 bfd;
826
  u8 bsd_secondary;
825 827

  
826 828
#ifdef OSPFv2
827 829
  list *passwords;
proto/ospf/packet.c
39 39
unsigned
40 40
ospf_pkt_maxsize(struct ospf_iface *ifa)
41 41
{
42
  unsigned mtu = (ifa->type == OSPF_IT_VLINK) ? OSPF_VLINK_MTU : ifa->iface->mtu;
43 42
  unsigned headers = SIZE_OF_IP_HEADER;
44 43

  
45 44
#ifdef OSPFv2
......
47 46
    headers += OSPF_AUTH_CRYPT_SIZE;
48 47
#endif
49 48

  
50
  return mtu - headers;
49
  return ifa->tx_length - headers;
51 50
}
52 51

  
53 52
#ifdef OSPFv2
......
263 262
    return 1;
264 263

  
265 264
  DBG("OSPF: RX hook called (iface %s, src %I, dst %I)\n",
266
      sk->iface->name, sk->faddr, sk->laddr);
265
      sk->ifname, sk->faddr, sk->laddr);
267 266

  
268 267
  /* Initially, the packet is associated with the 'master' iface */
269 268
  struct ospf_iface *ifa = sk->data;
......
321 320
    return 1;
322 321
  }
323 322

  
324
  int osize = ntohs(ps->length);
325
  if ((unsigned) osize < sizeof(struct ospf_packet))
323
  uint plen = ntohs(ps->length);
324
  if ((plen < sizeof(struct ospf_packet)) || ((plen % 4) != 0))
326 325
  {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff