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
200 // Internal errors
201 SCION_ERR_NOT_ENOUGH_DATA = -201,
202 SCION_ERR_PACKET_FIELD_INVALID = -202,
203 SCION_ERR_GRPC_FAIL = -203,
204 SCION_ERR_META_HDR_INVALID = -204,
205 SCION_ERR_PATH_TYPE_INVALID = -205,
206 SCION_ERR_SCMP_CODE_INVALID = -206,
207};
208
214char *scion_strerror(int err);
215
223 SCION_AF_INET = AF_INET,
227 SCION_AF_INET6 = AF_INET6
229
240 SCION_SOCK_DGRAM = SOCK_DGRAM,
244 SCION_SOCK_RAW = SOCK_RAW,
245};
246
262
266typedef uint64_t scion_ia;
267
275int scion_ia_parse(const char *str, size_t len, scion_ia *ia);
276
286int scion_ia_str(scion_ia ia, char *buf, size_t buflen);
287
293
301struct scion_topology;
302
309int scion_topology_from_file(struct scion_topology **topology, const char *path);
310
317
323
333int scion_bootstrap(const char *topology_path);
334
343struct scion_network;
344
351int scion_network(struct scion_network **net, struct scion_topology *topology);
352
358
365
371struct scion_path;
372
379
385size_t scion_path_get_numhops(const struct scion_path *path);
386
391void scion_path_free(struct scion_path *path);
392
397#define SCION_PATH_METADATA_LATENCY_IS_UNSET(latency) (latency.tv_sec == 0 && latency.tv_usec == -1)
402#define SCION_PATH_METADATA_BANDWIDTH_IS_UNSET(bandwidth) (bandwidth == 0)
407#define SCION_PATH_METADATA_GEO_IS_UNSET(geo) (geo.latitude == NAN && geo.longitude == NAN && geo.address == NULL)
412#define SCION_PATH_METADATA_INTERNAL_HOPS_IS_UNSET(internal_hops) (internal_hops == 0)
413
417typedef uint64_t scion_ifid;
418
434
454
476
487 size_t ases_len;
488
493 size_t interfaces_len;
494
498 uint32_t mtu;
502 int64_t expiry;
503
510 struct timeval *latencies;
511
518 uint64_t *bandwidths;
519
527
533
534 //
542 uint32_t *internal_hops;
543
548 char **notes;
549};
550
559
564void scion_path_print(const struct scion_path *path);
565
570void scion_path_print_metadata(const struct scion_path *path);
571
578
586typedef bool (*scion_path_predicate_fn)(struct scion_path *path, void *ctx);
587
603
613typedef int (*scion_path_comparator_fn)(struct scion_path *path_one, struct scion_path *path_two, void *ctx);
614
634
640
650 struct scion_path_collection *paths, struct scion_path_predicate predicate);
651
660
669
678
687
694
704
710
720 struct scion_network *network, scion_ia dst, uint opt, struct scion_path_collection **paths);
721
731typedef void (*scion_policy_fn)(struct scion_path_collection *paths, void *ctx);
732
741
745 void *ctx;
746};
747
751extern const struct scion_policy scion_policy_highest_mtu;
752
756extern const struct scion_policy scion_policy_least_hops;
757
761extern const struct scion_policy scion_policy_lowest_latency;
762
767
773struct scion_policy scion_policy_min_mtu(uint32_t *mtu);
774
780struct scion_socket;
781
790typedef void scion_socket_scmp_error_cb(uint8_t *buf, size_t size, void *ctx);
791
803int scion_socket(struct scion_socket **scion_sock, enum scion_addr_family addr_family, int type,
804 enum scion_proto protocol, struct scion_network *network);
805
813int scion_bind(struct scion_socket *scion_sock, const struct sockaddr *addr, socklen_t addrlen);
814
825int scion_connect(struct scion_socket *scion_sock, const struct sockaddr *addr, socklen_t addrlen, scion_ia ia);
826
838ssize_t scion_send(struct scion_socket *scion_sock, const void *buf, size_t size, int flags);
839
855ssize_t scion_sendto(struct scion_socket *scion_sock, const void *buf, size_t size, int flags,
856 const struct sockaddr *dst_addr, socklen_t addrlen, scion_ia dst_ia, struct scion_path *path);
857
870 struct scion_socket *scion_sock, const struct msghdr *msg, int flags, scion_ia dst_ia, struct scion_path *path);
871
884ssize_t scion_recv(struct scion_socket *scion_sock, void *buf, size_t size, int flags);
885
902ssize_t scion_recvfrom(struct scion_socket *scion_sock, void *buf, size_t size, int flags, struct sockaddr *src_addr,
903 socklen_t *addrlen, scion_ia *src_ia, struct scion_path **path);
904
917 struct scion_socket *scion_sock, struct msghdr *msg, int flags, scion_ia *src_ia, struct scion_path **path);
918
924int scion_close(struct scion_socket *scion_sock);
925
939int scion_getsockopt(struct scion_socket *scion_sock, int level, int optname, void *optval, socklen_t *optlen);
940
953int scion_setsockopt(struct scion_socket *scion_sock, int level, int optname, const void *optval, socklen_t optlen);
954
966int scion_getsockname(struct scion_socket *scion_sock, struct sockaddr *addr, socklen_t *addrlen, scion_ia *ia);
967
974int scion_getsockfd(struct scion_socket *scion_sock, int *fd);
975
983int scion_setsockerrcb(struct scion_socket *scion_sock, scion_socket_scmp_error_cb cb, void *ctx);
984
991int scion_setsockpolicy(struct scion_socket *scion_sock, struct scion_policy policy);
992
998void scion_addr_print(const struct sockaddr *addr, scion_ia ia);
999
1008uint8_t scion_scmp_get_type(const uint8_t *buf, uint16_t buf_len);
1009
1016uint8_t scion_scmp_get_code(const uint8_t *buf, uint16_t buf_len);
1017
1026bool scion_scmp_is_error(const uint8_t *buf, uint16_t buf_len);
1027
1045
1053 uint16_t id;
1055 uint16_t seqno;
1057 uint8_t *data;
1059 uint16_t data_length;
1060};
1061
1067uint16_t scion_scmp_echo_len(struct scion_scmp_echo *scmp_echo);
1068
1078int scion_scmp_echo_serialize(const struct scion_scmp_echo *scmp_echo, uint8_t *buf, uint16_t buf_len);
1079
1087int scion_scmp_echo_deserialize(const uint8_t *buf, uint16_t buf_len, struct scion_scmp_echo *scmp_echo);
1088
1094
1095#ifdef __cplusplus
1096}
1097#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:1031
@ SCION_ECHO_TYPE_REQUEST
Definition scion.h:1037
@ SCION_ECHO_TYPE_REPLY
Definition scion.h:1043
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:790
void scion_topology_free(struct scion_topology *topo)
ssize_t scion_sendmsg(struct scion_socket *scion_sock, const struct msghdr *msg, int flags, scion_ia dst_ia, struct scion_path *path)
void scion_path_collection_free(struct scion_path_collection *paths)
int scion_path_reverse(struct scion_path *path)
ssize_t scion_recvmsg(struct scion_socket *scion_sock, struct msghdr *msg, int flags, scion_ia *src_ia, struct scion_path **path)
scion_proto
Definition scion.h:250
@ SCION_PROTO_SCMP
Definition scion.h:260
@ SCION_PROTO_UDP
Definition scion.h:255
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_PROTO_INCOMPATIBLE
Definition scion.h:199
@ 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_SOCK_TYPE_UNKNOWN
Definition scion.h:195
@ 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:417
int scion_setsockpolicy(struct scion_socket *scion_sock, struct scion_policy policy)
int scion_bootstrap(const char *topology_path)
bool(* scion_path_predicate_fn)(struct scion_path *path, void *ctx)
Definition scion.h:586
void(* scion_policy_fn)(struct scion_path_collection *paths, void *ctx)
Definition scion.h:731
scion_addr_family
Definition scion.h:219
@ SCION_AF_INET
Definition scion.h:223
@ SCION_AF_INET6
Definition scion.h:227
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:613
uint64_t scion_ia
Definition scion.h:266
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)
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_sock_type
Definition scion.h:235
@ SCION_SOCK_DGRAM
Definition scion.h:240
@ SCION_SOCK_RAW
Definition scion.h:244
scion_link_type
Definition scion.h:458
@ SCION_LINK_TYPE_OPEN_NET
Definition scion.h:474
@ SCION_LINK_TYPE_MULTI_HOP
Definition scion.h:470
@ SCION_LINK_TYPE_DIRECT
Definition scion.h:466
@ SCION_LINK_TYPE_UNSPECIFIED
Definition scion.h:462
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:440
float latitude
Definition scion.h:444
float longitude
Definition scion.h:448
char * address
Definition scion.h:452
A network context in SCION.
A collection of SCION paths.
A path comparator.
Definition scion.h:620
bool ascending
Definition scion.h:632
scion_path_comparator_fn fn
Definition scion.h:624
void * ctx
Definition scion.h:628
An interface of an AS in a SCION path.
Definition scion.h:424
scion_ifid id
Definition scion.h:428
scion_ia ia
Definition scion.h:432
The metadata of a SCION path.
Definition scion.h:482
enum scion_link_type * link_types
Definition scion.h:532
struct timeval * latencies
Definition scion.h:510
struct scion_geo_coordinates * geo
Definition scion.h:526
int64_t expiry
Definition scion.h:502
uint64_t * bandwidths
Definition scion.h:518
uint32_t mtu
Definition scion.h:498
char ** notes
Definition scion.h:548
scion_ia * ases
Definition scion.h:486
struct scion_path_interface * interfaces
Definition scion.h:492
uint32_t * internal_hops
Definition scion.h:542
A path predicate.
Definition scion.h:593
void * ctx
Definition scion.h:601
scion_path_predicate_fn fn
Definition scion.h:597
A SCION path.
Definition scion.h:736
void * ctx
Definition scion.h:745
scion_policy_fn fn
Definition scion.h:740
Definition scion.h:1049
uint16_t data_length
Definition scion.h:1059
uint8_t * data
Definition scion.h:1057
uint16_t id
Definition scion.h:1053
uint16_t seqno
Definition scion.h:1055
enum scion_scmp_echo_type type
Definition scion.h:1051
A SCION socket.
A topology context in SCION.