csnet
Loading...
Searching...
No Matches
scion.h
Go to the documentation of this file.
1// Copyright 2024 ETH Zurich
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
21#pragma once
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27#include <stdbool.h>
28#include <stdint.h>
29#include <sys/socket.h>
30#include <sys/time.h>
31
32#define SCION_SO_DEBUG 200
33
34#define SCION_FETCH_OPT_DEBUG 1
35
39#define SCION_IA_STRLEN 21
40
198
204char *scion_strerror(int err);
205
213 SCION_AF_INET = AF_INET,
217 SCION_AF_INET6 = AF_INET6
219
235
239typedef uint64_t scion_ia;
240
248int scion_ia_parse(const char *str, size_t len, scion_ia *ia);
249
259int scion_ia_str(scion_ia ia, char *buf, size_t buflen);
260
266
274struct scion_topology;
275
282int scion_topology_from_file(struct scion_topology **topology, const char *path);
283
290
296
306int scion_bootstrap(const char *topology_output_path);
307
316struct scion_network;
317
324int scion_network(struct scion_network **net, struct scion_topology *topology);
325
331
338
344struct scion_path;
345
352
358size_t scion_path_get_numhops(const struct scion_path *path);
359
364void scion_path_free(struct scion_path *path);
365
370#define SCION_PATH_METADATA_LATENCY_IS_UNSET(latency) (latency.tv_sec == 0 && latency.tv_usec == -1)
375#define SCION_PATH_METADATA_BANDWIDTH_IS_UNSET(bandwidth) (bandwidth == 0)
380#define SCION_PATH_METADATA_GEO_IS_UNSET(geo) (geo.latitude == NAN && geo.longitude == NAN && geo.address == NULL)
385#define SCION_PATH_METADATA_INTERNAL_HOPS_IS_UNSET(internal_hops) (internal_hops == 0)
386
390typedef uint64_t scion_ifid;
391
407
427
449
460 size_t ases_len;
461
466 size_t interfaces_len;
467
471 uint32_t mtu;
475 int64_t expiry;
476
483 struct timeval *latencies;
484
491 uint64_t *bandwidths;
492
500
506
507 //
515 uint32_t *internal_hops;
516
521 char **notes;
522};
523
532
537void scion_path_print(const struct scion_path *path);
538
543void scion_path_print_metadata(const struct scion_path *path);
544
551
559typedef bool (*scion_path_predicate_fn)(struct scion_path *path, void *ctx);
560
576
586typedef int (*scion_path_comparator_fn)(struct scion_path *path_one, struct scion_path *path_two, void *ctx);
587
607
613
623 struct scion_path_collection *paths, struct scion_path_predicate predicate);
624
633
642
651
660
667
677
683
692int scion_path_collection_fetch(struct scion_network *network, scion_ia dst, uint opt, struct scion_path_collection **paths);
693
703typedef void (*scion_policy_fn)(struct scion_path_collection *paths, void *ctx);
704
713
717 void *ctx;
718};
719
723extern const struct scion_policy scion_policy_highest_mtu;
724
728extern const struct scion_policy scion_policy_least_hops;
729
733extern const struct scion_policy scion_policy_lowest_latency;
734
739
745struct scion_policy scion_policy_min_mtu(uint32_t *mtu);
746
752struct scion_socket;
753
762typedef void scion_socket_scmp_error_cb(uint8_t *buf, size_t size, void *ctx);
763
773int scion_socket(struct scion_socket **scion_sock, enum scion_addr_family addr_family, enum scion_proto protocol,
774 struct scion_network *network);
775
783int scion_bind(struct scion_socket *scion_sock, const struct sockaddr *addr, socklen_t addrlen);
784
795int scion_connect(struct scion_socket *scion_sock, const struct sockaddr *addr, socklen_t addrlen, scion_ia ia);
796
808ssize_t scion_send(struct scion_socket *scion_sock, const void *buf, size_t size, int flags);
809
825ssize_t scion_sendto(struct scion_socket *scion_sock, const void *buf, size_t size, int flags,
826 const struct sockaddr *dst_addr, socklen_t addrlen, scion_ia dst_ia, struct scion_path *path);
827
840ssize_t scion_recv(struct scion_socket *scion_sock, void *buf, size_t size, int flags);
841
858ssize_t scion_recvfrom(struct scion_socket *scion_sock, void *buf, size_t size, int flags, struct sockaddr *src_addr,
859 socklen_t *addrlen, scion_ia *src_ia, struct scion_path **path);
860
866int scion_close(struct scion_socket *scion_sock);
867
881int scion_getsockopt(struct scion_socket *scion_sock, int level, int optname, void *optval, socklen_t *optlen);
882
895int scion_setsockopt(struct scion_socket *scion_sock, int level, int optname, const void *optval, socklen_t optlen);
896
908int scion_getsockname(struct scion_socket *scion_sock, struct sockaddr *addr, socklen_t *addrlen, scion_ia *ia);
909
916int scion_getsockfd(struct scion_socket *scion_sock, int *fd);
917
925int scion_setsockerrcb(struct scion_socket *scion_sock, scion_socket_scmp_error_cb cb, void *ctx);
926
933int scion_setsockpolicy(struct scion_socket *scion_sock, struct scion_policy policy);
934
940void scion_addr_print(const struct sockaddr *addr, scion_ia ia);
941
950uint8_t scion_scmp_get_type(const uint8_t *buf, uint16_t buf_len);
951
958uint8_t scion_scmp_get_code(const uint8_t *buf, uint16_t buf_len);
959
968bool scion_scmp_is_error(const uint8_t *buf, uint16_t buf_len);
969
987
995 uint16_t id;
997 uint16_t seqno;
999 uint8_t *data;
1001 uint16_t data_length;
1002};
1003
1009uint16_t scion_scmp_echo_len(struct scion_scmp_echo *scmp_echo);
1010
1020int scion_scmp_echo_serialize(const struct scion_scmp_echo *scmp_echo, uint8_t *buf, uint16_t buf_len);
1021
1029int scion_scmp_echo_deserialize(const uint8_t *buf, uint16_t buf_len, struct scion_scmp_echo *scmp_echo);
1030
1036
1037#ifdef __cplusplus
1038}
1039#endif
const struct scion_policy scion_policy_least_hops
int scion_scmp_echo_deserialize(const uint8_t *buf, uint16_t buf_len, struct scion_scmp_echo *scmp_echo)
int scion_scmp_echo_serialize(const struct scion_scmp_echo *scmp_echo, uint8_t *buf, uint16_t buf_len)
const struct scion_path_metadata * scion_path_get_metadata(const struct scion_path *path)
int scion_setsockerrcb(struct scion_socket *scion_sock, scion_socket_scmp_error_cb cb, void *ctx)
void scion_ia_print(scion_ia ia)
int scion_setsockopt(struct scion_socket *scion_sock, int level, int optname, const void *optval, socklen_t optlen)
struct scion_policy scion_policy_min_mtu(uint32_t *mtu)
const struct scion_policy scion_policy_highest_mtu
void scion_addr_print(const struct sockaddr *addr, scion_ia ia)
ssize_t scion_recvfrom(struct scion_socket *scion_sock, void *buf, size_t size, int flags, struct sockaddr *src_addr, socklen_t *addrlen, scion_ia *src_ia, struct scion_path **path)
int scion_getsockname(struct scion_socket *scion_sock, struct sockaddr *addr, socklen_t *addrlen, scion_ia *ia)
scion_scmp_echo_type
Definition scion.h:973
@ SCION_ECHO_TYPE_REQUEST
Definition scion.h:979
@ SCION_ECHO_TYPE_REPLY
Definition scion.h:985
void scion_path_free(struct scion_path *path)
ssize_t scion_send(struct scion_socket *scion_sock, const void *buf, size_t size, int flags)
int scion_getsockfd(struct scion_socket *scion_sock, int *fd)
int scion_bind(struct scion_socket *scion_sock, const struct sockaddr *addr, socklen_t addrlen)
uint8_t scion_scmp_get_code(const uint8_t *buf, uint16_t buf_len)
int scion_ia_str(scion_ia ia, char *buf, size_t buflen)
void scion_network_free(struct scion_network *net)
void scion_socket_scmp_error_cb(uint8_t *buf, size_t size, void *ctx)
Definition scion.h:762
void scion_topology_free(struct scion_topology *topo)
void scion_path_collection_free(struct scion_path_collection *paths)
int scion_path_reverse(struct scion_path *path)
scion_proto
Definition scion.h:223
@ SCION_PROTO_SCMP
Definition scion.h:233
@ SCION_PROTO_UDP
Definition scion.h:228
const struct scion_policy scion_policy_highest_bandwidth
void scion_path_print_metadata(const struct scion_path *path)
size_t scion_path_get_numhops(const struct scion_path *path)
void scion_path_collection_sort(struct scion_path_collection *paths, struct scion_path_comparator comparator)
char * scion_strerror(int err)
scion_error
Definition scion.h:46
@ SCION_ERR_NETWORK_ADDR_FAMILY_MISMATCH
Definition scion.h:90
@ SCION_ERR_DST_MISMATCH
Definition scion.h:104
@ SCION_ERR_MAX_HDR_LEN_EXCEEDED
Definition scion.h:72
@ SCION_ERR_RECV_FAIL
Definition scion.h:136
@ SCION_ERR_ADDR_FAMILY_UNKNOWN
Definition scion.h:68
@ SCION_ERR_ADDR_BUF_TOO_SMALL
Definition scion.h:162
@ SCION_ERR_BUF_TOO_SMALL
Definition scion.h:62
@ SCION_ERR_ALREADY_BOUND
Definition scion.h:120
@ SCION_ERR_PROTO_UNKNOWN
Definition scion.h:96
@ SCION_ERR_INVALID_ISD_AS_STR
Definition scion.h:108
@ SCION_ERR_ADDR_IN_USE
Definition scion.h:142
@ SCION_ERR_NOT_BOUND
Definition scion.h:170
@ SCION_ERR_ADDR_NOT_AVAILABLE
Definition scion.h:148
@ SCION_ERR_NETWORK_UNKNOWN
Definition scion.h:174
@ SCION_ERR_TOPOLOGY_INVALID
Definition scion.h:80
@ SCION_ERR_ADDR_FAMILY_MISMATCH
Definition scion.h:86
@ SCION_ERR_BOOTSTRAPPING_FAIL
Definition scion.h:189
@ SCION_ERR_SRC_ADDR_UNKNOWN
Definition scion.h:185
@ SCION_ERR_NOT_CONNECTED
Definition scion.h:100
@ SCION_ERR_OUTPUT_QUEUE_FULL
Definition scion.h:154
@ SCION_ERR_MEM_ALLOC_FAIL
Definition scion.h:54
@ SCION_ERR_MSG_TOO_LARGE
Definition scion.h:178
@ SCION_ERR_GENERIC
Definition scion.h:50
@ SCION_ERR_PATH_EXPIRED
Definition scion.h:166
@ SCION_ERR_FILE_NOT_FOUND
Definition scion.h:76
@ SCION_ERR_FLAG_NOT_IMPLEMENTED
Definition scion.h:124
@ SCION_ERR_FLAG_NOT_SUPPORTED
Definition scion.h:128
@ SCION_ERR_SEND_FAIL
Definition scion.h:132
@ SCION_ERR_SOCK_OPT_INVALID
Definition scion.h:158
@ SCION_ERR_WOULD_BLOCK
Definition scion.h:112
@ SCION_ERR_NO_PATHS
Definition scion.h:58
@ SCION_ERR_ADDR_INVALID
Definition scion.h:116
struct scion_path * scion_path_collection_first(struct scion_path_collection *paths)
uint16_t scion_scmp_echo_len(struct scion_scmp_echo *scmp_echo)
uint64_t scion_ifid
Definition scion.h:390
int scion_setsockpolicy(struct scion_socket *scion_sock, struct scion_policy policy)
bool(* scion_path_predicate_fn)(struct scion_path *path, void *ctx)
Definition scion.h:559
void(* scion_policy_fn)(struct scion_path_collection *paths, void *ctx)
Definition scion.h:703
scion_addr_family
Definition scion.h:209
@ SCION_AF_INET
Definition scion.h:213
@ SCION_AF_INET6
Definition scion.h:217
scion_ia scion_topology_get_local_ia(struct scion_topology *topo)
int(* scion_path_comparator_fn)(struct scion_path *path_one, struct scion_path *path_two, void *ctx)
Definition scion.h:586
uint64_t scion_ia
Definition scion.h:239
enum scion_addr_family scion_network_get_local_addr_family(struct scion_network *net)
int scion_topology_from_file(struct scion_topology **topology, const char *path)
uint8_t scion_scmp_get_type(const uint8_t *buf, uint16_t buf_len)
int scion_ia_parse(const char *str, size_t len, scion_ia *ia)
ssize_t scion_recv(struct scion_socket *scion_sock, void *buf, size_t size, int flags)
void scion_path_print(const struct scion_path *path)
int scion_path_collection_fetch(struct scion_network *network, scion_ia dst, uint opt, struct scion_path_collection **paths)
struct scion_path * scion_path_collection_pop(struct scion_path_collection *paths)
int scion_close(struct scion_socket *scion_sock)
int scion_getsockopt(struct scion_socket *scion_sock, int level, int optname, void *optval, socklen_t *optlen)
void scion_scmp_echo_free_members(struct scion_scmp_echo *scmp_echo)
int scion_bootstrap(const char *topology_output_path)
bool scion_scmp_is_error(const uint8_t *buf, uint16_t buf_len)
struct scion_path ** scion_path_collection_as_array(struct scion_path_collection *paths, size_t *len)
int scion_connect(struct scion_socket *scion_sock, const struct sockaddr *addr, socklen_t addrlen, scion_ia ia)
size_t scion_path_collection_size(struct scion_path_collection *paths)
scion_link_type
Definition scion.h:431
@ SCION_LINK_TYPE_OPEN_NET
Definition scion.h:447
@ SCION_LINK_TYPE_MULTI_HOP
Definition scion.h:443
@ SCION_LINK_TYPE_DIRECT
Definition scion.h:439
@ SCION_LINK_TYPE_UNSPECIFIED
Definition scion.h:435
const struct scion_policy scion_policy_lowest_latency
void scion_path_collection_filter(struct scion_path_collection *paths, struct scion_path_predicate predicate)
void scion_path_collection_print(struct scion_path_collection *paths)
struct scion_path * scion_path_collection_find(struct scion_path_collection *paths, struct scion_path_predicate predicate)
ssize_t scion_sendto(struct scion_socket *scion_sock, const void *buf, size_t size, int flags, const struct sockaddr *dst_addr, socklen_t addrlen, scion_ia dst_ia, struct scion_path *path)
The geographic location of an AS.
Definition scion.h:413
float latitude
Definition scion.h:417
float longitude
Definition scion.h:421
char * address
Definition scion.h:425
A network context in SCION.
A collection of SCION paths.
A path comparator.
Definition scion.h:593
bool ascending
Definition scion.h:605
scion_path_comparator_fn fn
Definition scion.h:597
void * ctx
Definition scion.h:601
An interface of an AS in a SCION path.
Definition scion.h:397
scion_ifid id
Definition scion.h:401
scion_ia ia
Definition scion.h:405
The metadata of a SCION path.
Definition scion.h:455
enum scion_link_type * link_types
Definition scion.h:505
struct timeval * latencies
Definition scion.h:483
struct scion_geo_coordinates * geo
Definition scion.h:499
int64_t expiry
Definition scion.h:475
uint64_t * bandwidths
Definition scion.h:491
uint32_t mtu
Definition scion.h:471
char ** notes
Definition scion.h:521
scion_ia * ases
Definition scion.h:459
struct scion_path_interface * interfaces
Definition scion.h:465
uint32_t * internal_hops
Definition scion.h:515
A path predicate.
Definition scion.h:566
void * ctx
Definition scion.h:574
scion_path_predicate_fn fn
Definition scion.h:570
A SCION path.
Definition scion.h:708
void * ctx
Definition scion.h:717
scion_policy_fn fn
Definition scion.h:712
Definition scion.h:991
uint16_t data_length
Definition scion.h:1001
uint8_t * data
Definition scion.h:999
uint16_t id
Definition scion.h:995
uint16_t seqno
Definition scion.h:997
enum scion_scmp_echo_type type
Definition scion.h:993
A SCION socket.
A topology context in SCION.