@@ -427,109 +427,6 @@ static bool add_channel_direction(struct routing_state *rstate,
427
427
return true;
428
428
}
429
429
430
- /* BOLT #7:
431
- *
432
- * The following `address descriptor` types are defined:
433
- *
434
- * * `0`: padding. data = none (length 0).
435
- * * `1`: ipv4. data = `[4:ipv4_addr][2:port]` (length 6)
436
- * * `2`: ipv6. data = `[16:ipv6_addr][2:port]` (length 18)
437
- */
438
-
439
- /* FIXME: Don't just take first one, depends whether we have IPv6 ourselves */
440
- /* Returns false iff it was malformed */
441
- bool read_ip (const tal_t * ctx , const u8 * addresses , char * * hostname ,
442
- int * port )
443
- {
444
- size_t len = tal_count (addresses );
445
- const u8 * p = addresses ;
446
- char tempaddr [INET6_ADDRSTRLEN ];
447
- be16 portnum ;
448
-
449
- * hostname = NULL ;
450
- while (len ) {
451
- u8 type = * p ;
452
- p ++ ;
453
- len -- ;
454
-
455
- switch (type ) {
456
- case 0 :
457
- break ;
458
- case 1 :
459
- /* BOLT #7:
460
- *
461
- * The receiving node SHOULD fail the connection if
462
- * `addrlen` is insufficient to hold the address
463
- * descriptors of the known types.
464
- */
465
- if (len < 6 )
466
- return false;
467
- inet_ntop (AF_INET , p , tempaddr , sizeof (tempaddr ));
468
- memcpy (& portnum , p + 4 , sizeof (portnum ));
469
- * hostname = tal_strdup (ctx , tempaddr );
470
- * port = be16_to_cpu (portnum );
471
- return true;
472
- case 2 :
473
- if (len < 18 )
474
- return false;
475
- inet_ntop (AF_INET6 , p , tempaddr , sizeof (tempaddr ));
476
- memcpy (& portnum , p + 16 , sizeof (portnum ));
477
- * hostname = tal_strdup (ctx , tempaddr );
478
- * port = be16_to_cpu (portnum );
479
- return true;
480
- default :
481
- /* BOLT #7:
482
- *
483
- * The receiving node SHOULD ignore the first `address
484
- * descriptor` which does not match the types defined
485
- * above.
486
- */
487
- return true;
488
- }
489
- }
490
-
491
- /* Not a fatal error. */
492
- return true;
493
- }
494
-
495
- /* BOLT #7:
496
- *
497
- * The creating node SHOULD fill `addresses` with an address descriptor for
498
- * each public network address which expects incoming connections, and MUST
499
- * set `addrlen` to the number of bytes in `addresses`. Non-zero typed
500
- * address descriptors MUST be placed in ascending order; any number of
501
- * zero-typed address descriptors MAY be placed anywhere, but SHOULD only be
502
- * used for aligning fields following `addresses`.
503
- *
504
- * The creating node MUST NOT create a type 1 or type 2 address descriptor
505
- * with `port` equal to zero, and SHOULD ensure `ipv4_addr` and `ipv6_addr`
506
- * are routable addresses. The creating node MUST NOT include more than one
507
- * `address descriptor` of the same type.
508
- */
509
- /* FIXME: handle case where we have both ipv6 and ipv4 addresses! */
510
- u8 * write_ip (const tal_t * ctx , const char * srcip , int port )
511
- {
512
- u8 * address ;
513
- be16 portnum = cpu_to_be16 (port );
514
-
515
- if (!port )
516
- return tal_arr (ctx , u8 , 0 );
517
-
518
- if (!strchr (srcip , ':' )) {
519
- address = tal_arr (ctx , u8 , 7 );
520
- address [0 ] = 1 ;
521
- inet_pton (AF_INET , srcip , address + 1 );
522
- memcpy (address + 5 , & portnum , sizeof (portnum ));
523
- return address ;
524
- } else {
525
- address = tal_arr (ctx , u8 , 18 );
526
- address [0 ] = 2 ;
527
- inet_pton (AF_INET6 , srcip , address + 1 );
528
- memcpy (address + 17 , & portnum , sizeof (portnum ));
529
- return address ;
530
- }
531
- }
532
-
533
430
/* Verify the signature of a channel_update message */
534
431
static bool check_channel_update (const struct pubkey * node_key ,
535
432
const secp256k1_ecdsa_signature * node_sig ,
@@ -731,20 +628,32 @@ void handle_channel_update(struct routing_state *rstate, const u8 *update, size_
731
628
tal_free (tmpctx );
732
629
}
733
630
734
- static struct ipaddr * read_addresses (const tal_t * ctx , u8 * ser )
631
+ static struct ipaddr * read_addresses (const tal_t * ctx , const u8 * ser )
735
632
{
736
633
const u8 * cursor = ser ;
737
634
size_t max = tal_len (ser );
738
635
struct ipaddr * ipaddrs = tal_arr (ctx , struct ipaddr , 0 );
739
636
int numaddrs = 0 ;
740
- while (cursor < ser + max ) {
741
- numaddrs ++ ;
742
- tal_resize (& ipaddrs , numaddrs );
743
- fromwire_ipaddr (& cursor , & max , & ipaddrs [numaddrs - 1 ]);
744
- if (cursor == NULL ) {
745
- /* Parsing address failed */
746
- return tal_free (ipaddrs );
637
+ while (cursor && cursor < ser + max ) {
638
+ struct ipaddr ipaddr ;
639
+
640
+ /* BOLT #7:
641
+ *
642
+ * The receiving node SHOULD ignore the first `address
643
+ * descriptor` which does not match the types defined
644
+ * above.
645
+ */
646
+ if (!fromwire_ipaddr (& cursor , & max , & ipaddr )) {
647
+ if (!cursor )
648
+ /* Parsing address failed */
649
+ return tal_free (ipaddrs );
650
+ /* Unknown type, stop there. */
651
+ break ;
747
652
}
653
+
654
+ tal_resize (& ipaddrs , numaddrs + 1 );
655
+ ipaddrs [numaddrs ] = ipaddr ;
656
+ numaddrs ++ ;
748
657
}
749
658
return ipaddrs ;
750
659
}
0 commit comments