00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef LIBDHCP_NIC_H
00029 #define LIBDHCP_NIC_H
00030
00031 #include <sys/types.h>
00032 #include <sys/queue.h>
00033 #include <netinet/in.h>
00034 #include <net/if.h>
00035 #include <stdint.h>
00036 #include <stdarg.h>
00037 #include <ip_addr.h>
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 struct nic_s;
00048 typedef struct nic_s *NIC_t;
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 struct nic_ip_address_s;
00059 typedef struct nic_ip_address_s *IPaddr_t;
00060
00061 typedef
00062 struct nic_ip_address_list_node_s
00063 {
00064 IPaddr_t addr;
00065 STAILQ_ENTRY( nic_ip_address_list_node_s ) link;
00066 } IPaddr_list_node_t;
00067
00068 typedef
00069 STAILQ_HEAD(nic_ip_address_list_s,nic_ip_address_list_node_s)
00070 IPaddr_list_t;
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080 struct nic_route_s;
00081 typedef struct nic_route_s *IProute_t;
00082
00083 typedef
00084 struct nic_ip_route_node_s
00085 {
00086 IProute_t route;
00087 STAILQ_ENTRY( nic_ip_route_node_s ) link;
00088 } IProute_list_node_t;
00089
00090 typedef
00091 STAILQ_HEAD(nic_ip_route_list_s,nic_ip_route_node_s)
00092 IProute_list_t;
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 typedef struct nlh_s *NLH_t;
00105
00106
00107
00108
00109
00110 typedef
00111 enum nic_error_level_e
00112 {
00113 NIC_FATAL,
00114 NIC_ERR=3,
00115 NIC_WARN=4,
00116 NIC_DEBUG=7
00117 } NIC_Error_Level_t;
00118
00119
00120
00121
00122 typedef
00123 enum nic_result_e
00124 {
00125 NIC_FAIL = -1,
00126 NIC_OK = 0,
00127 NIC_SUCCESS=0
00128
00129 } NIC_Res_t;
00130
00131
00132
00133
00134 typedef void (*NIC_Error_Handler_t)( NLH_t, NIC_Error_Level_t, char*, ...);
00135
00136
00137
00138
00139 extern
00140 NLH_t nic_open( NIC_Error_Handler_t );
00141
00142
00143
00144
00145 extern
00146 void nic_close(NLH_t*);
00147
00148
00149
00150
00151 extern
00152 void nic_set_logger(NLH_t, NIC_Error_Handler_t );
00153
00154 typedef int (*NIC_VA_Error_Handler_t)(void*, int priority, char *fmt, va_list va);
00155
00156 extern
00157 void nic_set_va_logger(NLH_t, NIC_VA_Error_Handler_t handler, void *handler_arg );
00158
00159 extern
00160 void nic_sys_logger( NLH_t, NIC_Error_Level_t, char *fmt, ... );
00161
00162 extern
00163 void nic_stderr_logger( NLH_t, NIC_Error_Level_t, char *fmt, ... );
00164
00165 extern
00166 NIC_Res_t nic_set_loglevel( NLH_t, NIC_Error_Level_t );
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177 extern
00178 NIC_t nic_by_name(NLH_t, char * );
00179
00180 extern
00181 NIC_t nic_by_index(NLH_t, int16_t );
00182
00183 typedef void (*NIC_handler_t)(NLH_t nh, NIC_t, void*);
00184
00185 extern void nic_foreach(NLH_t nh, NIC_handler_t handler, void *arg);
00186
00187
00188
00189
00190
00191
00192 extern
00193 char *nic_get_name( NIC_t );
00194
00195 extern
00196 int16_t nic_get_index( NIC_t );
00197
00198 extern
00199 ip_addr_t nic_get_link_addr(NIC_t);
00200
00201
00202
00203 extern
00204 ip_addr_t nic_get_link_broadcast(NIC_t);
00205
00206
00207
00208 extern
00209 NIC_Res_t nic_update( NIC_t nic );
00210
00211
00212
00213
00214
00215 extern
00216 uint32_t nic_get_flags( NIC_t );
00217
00218 extern
00219 void nic_set_flags( NIC_t, uint32_t );
00220
00221 extern
00222 uint32_t nic_get_mtu( NIC_t );
00223
00224 extern
00225 void nic_set_mtu( NIC_t, uint32_t );
00226
00227 extern
00228 char *nic_get_qdisc( NIC_t );
00229
00230 extern
00231 void nic_set_qdisc( NIC_t, char * );
00232
00233 extern
00234 uint32_t nic_get_txqlen( NIC_t );
00235
00236 extern
00237 void nic_set_txqlen( NIC_t, uint32_t );
00238
00239 extern
00240 uint32_t nic_get_link( NIC_t );
00241
00242 extern
00243 void nic_set_link( NIC_t, uint32_t );
00244
00245 extern
00246 uint32_t nic_get_weight( NIC_t );
00247
00248 extern
00249 void nic_set_weight( NIC_t, uint32_t );
00250
00251 extern
00252 uint32_t nic_get_master( NIC_t );
00253
00254 extern
00255 void nic_set_master( NIC_t, uint32_t );
00256
00257 extern
00258 uint32_t nic_get_cost( NIC_t );
00259
00260 extern
00261 void nic_set_cost( NIC_t, uint32_t );
00262
00263 extern
00264 uint32_t nic_get_priority( NIC_t );
00265
00266 extern
00267 void nic_set_priority( NIC_t, uint32_t );
00268
00269 extern
00270 uint32_t nic_get_protinfo( NIC_t );
00271
00272 extern
00273 void nic_set_protinfo( NIC_t, uint32_t );
00274
00275 struct rtnl_link_stats;
00276 extern
00277 struct rtnl_link_stats nic_get_stats(NIC_t);
00278
00279 struct rtnl_link_ifmap;
00280 extern
00281 struct rtnl_link_ifmap nic_get_ifmap(NIC_t);
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293 typedef void (*IPaddr_Handler_t) (NLH_t nh, IPaddr_t, void *);
00294
00295 extern
00296 void nic_addr_foreach( NLH_t, IPaddr_Handler_t, void * );
00297
00298
00299 extern
00300 IPaddr_t nic_addr_ip( NLH_t nh, ip_addr_t *);
00301
00302 extern
00303 ip_addr_t nic_ip_addr( IPaddr_t );
00304
00305 extern
00306 IPaddr_t nic_addr( NLH_t nh, ip_addr_t);
00307
00308 extern
00309 IPaddr_t nic_addr_local( NLH_t nh, ip_addr_t);
00310
00311 extern
00312 ip_addr_t nic_addr_get_local( IPaddr_t );
00313
00314 extern
00315 void nic_addr_set_local( IPaddr_t, ip_addr_t);
00316
00317 extern
00318 uint8_t nic_addr_get_family( IPaddr_t );
00319
00320 extern
00321 uint8_t nic_addr_get_prefix( IPaddr_t );
00322
00323 extern
00324 void nic_addr_set_prefix( IPaddr_t, uint8_t );
00325
00326 extern
00327 ip_addr_t nic_addr_get_broadcast( IPaddr_t );
00328
00329 extern
00330 void nic_addr_set_broadcast( IPaddr_t, ip_addr_t );
00331
00332 extern
00333 ip_addr_t nic_addr_get_anycast( IPaddr_t );
00334
00335 extern
00336 void nic_addr_set_anycast( IPaddr_t, ip_addr_t);
00337
00338 extern
00339 ip_addr_t nic_addr_get_multicast( IPaddr_t );
00340
00341 extern
00342 void nic_addr_set_multicast( IPaddr_t, ip_addr_t);
00343
00344 extern
00345 int8_t nic_addr_get_scope(IPaddr_t);
00346
00347 extern
00348 void nic_addr_set_scope(IPaddr_t, int8_t);
00349
00350 extern
00351 uint8_t nic_addr_get_flags(IPaddr_t);
00352
00353 extern
00354 void nic_addr_set_flags(IPaddr_t, uint8_t);
00355
00356 extern
00357 const char *nic_addr_get_label(IPaddr_t);
00358
00359 extern
00360 void nic_addr_set_label(IPaddr_t, const char *);
00361
00362 struct ifa_cacheinfo;
00363
00364 extern
00365 struct ifa_cacheinfo nic_addr_get_cacheinfo( IPaddr_t );
00366
00367 extern
00368 void nic_addr_set_cacheinfo( IPaddr_t, struct ifa_cacheinfo* );
00369
00370 extern
00371 IPaddr_list_t *nic_address_list_new( IPaddr_t, ... );
00372
00373
00374 extern
00375 void nic_address_list_free( IPaddr_list_t *);
00376
00377 extern
00378 NIC_Res_t nic_add_address( NIC_t, IPaddr_t );
00379
00380 extern
00381 NIC_Res_t nic_remove_address( NIC_t, IPaddr_t );
00382
00383 extern
00384 NIC_Res_t nic_add_addresses( NIC_t, IPaddr_list_t* );
00385
00386 extern
00387 NIC_Res_t nic_remove_addresses( NIC_t, IPaddr_list_t* );
00388
00389 void nic_addr_free(void *);
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399 typedef void (*IProute_handler_t) (NLH_t nh, IProute_t, void *);
00400
00401 extern
00402 void nic_route_foreach( NLH_t, IProute_handler_t, void * );
00403
00404
00405 extern
00406 int32_t nic_route_get_table(IProute_t);
00407
00408 extern
00409 void nic_route_set_table(IProute_t, uint8_t table);
00410
00411 extern
00412 char *nic_route_get_table_name( int32_t, char *buf, int len );
00413
00414 extern
00415 int32_t nic_route_get_table_number( char* );
00416
00417 extern
00418 uint8_t nic_route_get_family( IProute_t );
00419
00420 extern
00421 uint8_t nic_route_get_scope(IProute_t);
00422
00423 extern
00424 void nic_route_set_scope(IProute_t, uint8_t);
00425
00426 extern
00427 uint32_t nic_route_get_flags( IProute_t );
00428
00429 extern
00430 void nic_route_set_flags( IProute_t, uint32_t );
00431
00432 extern
00433 uint8_t nic_route_get_dst_len( IProute_t );
00434
00435 extern
00436 void nic_route_set_dst_len( IProute_t, uint8_t );
00437
00438 extern
00439 uint8_t nic_route_get_src_len( IProute_t );
00440
00441 extern
00442 void nic_route_set_src_len( IProute_t, uint8_t );
00443
00444 extern
00445 uint8_t nic_route_get_type( IProute_t );
00446
00447 extern
00448 void nic_route_set_type( IProute_t, uint8_t );
00449
00450 extern
00451 uint8_t nic_route_get_protocol( IProute_t );
00452
00453 extern
00454 void nic_route_set_protocol( IProute_t, uint8_t );
00455
00456 extern
00457 uint8_t nic_route_get_tos( IProute_t);
00458
00459 extern
00460 void nic_route_set_tos( IProute_t, uint8_t);
00461
00462 extern
00463 ip_addr_t nic_route_get_dst( IProute_t );
00464
00465 extern
00466 void nic_route_set_dst(IProute_t, ip_addr_t);
00467
00468 extern
00469 ip_addr_t nic_route_get_src( IProute_t );
00470
00471 extern
00472 void nic_route_set_src(IProute_t, ip_addr_t);
00473
00474 extern
00475 ip_addr_t nic_route_get_gateway( IProute_t );
00476
00477 extern
00478 void nic_route_set_gateway(IProute_t, ip_addr_t);
00479
00480 extern
00481 ip_addr_t nic_route_get_prefsrc( IProute_t );
00482
00483 extern
00484 void nic_route_set_prefsrc(IProute_t, ip_addr_t);
00485
00486 extern
00487 int16_t nic_route_get_oif( IProute_t );
00488
00489 extern
00490 void nic_route_set_oif( IProute_t, uint16_t);
00491
00492 typedef
00493 struct nic_if_name_s
00494 { char name [ IFNAMSIZ ];
00495 } NIC_if_name_t;
00496
00497 extern
00498 NIC_if_name_t nic_route_get_iif( IProute_t );
00499
00500 extern
00501 void nic_route_set_iif( IProute_t, char * );
00502
00503 extern
00504 uint32_t nic_route_get_priority( IProute_t );
00505
00506 extern
00507 void nic_route_set_priority( IProute_t, uint32_t );
00508
00509 extern
00510 uint32_t nic_route_get_protoinfo(IProute_t);
00511
00512 extern
00513 void nic_route_set_protoinfo(IProute_t, uint32_t);
00514
00515 extern
00516 uint32_t nic_route_get_session(IProute_t);
00517
00518 extern
00519 void nic_route_set_session(IProute_t, uint32_t);
00520
00521 extern
00522 uint32_t nic_route_get_flow(IProute_t);
00523
00524 extern
00525 void nic_route_set_flow(IProute_t, uint32_t);
00526
00527 extern
00528 uint32_t nic_route_get_mp_algo(IProute_t);
00529
00530 extern
00531 void nic_route_mp_algo(IProute_t, uint32_t);
00532
00533 extern
00534 IProute_t nic_route_new
00535 ( NLH_t,
00536 int16_t oif,
00537 ip_addr_t *dst,
00538 #define NIC_ROUTE_DEFAULT_ADDR ((ip_addr_t*)0L)
00539 uint8_t dst_len,
00540 ip_addr_t *gw,
00541 int8_t type,
00542 int8_t protocol,
00543 int8_t scope,
00544 int32_t priority,
00545 int32_t table,
00546 char* iif,
00547 ip_addr_t *src,
00548 uint8_t src_len
00549 #define NIC_ROUTE_NO_IF (-1)
00550 );
00551
00552 extern
00553 void nic_route_free(void *);
00554
00555 extern
00556 NIC_Res_t nic_add_route( IProute_t );
00557
00558 extern
00559 NIC_Res_t nic_update_route( IProute_t );
00560
00561 extern
00562 NIC_Res_t nic_remove_route( IProute_t );
00563
00564 extern
00565 IProute_list_t *nic_route_list_new( IProute_t, ... );
00566
00567
00568 void nic_route_list_free( IProute_list_t* );
00569
00570 extern
00571 NIC_Res_t nic_add_routes( IProute_list_t* );
00572
00573 extern
00574 NIC_Res_t nic_remove_routes( IProute_list_t* );
00575
00576 extern
00577 NIC_Res_t nic_update_routes( IProute_list_t* );
00578
00579 struct rtnl_route *nic_rtnl_route_get(IProute_t);
00580 void nic_rtnl_route_put(struct rtnl_route *);
00581
00582
00583
00584
00585
00586 extern void nic_free_route( IProute_t );
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598 extern
00599 NIC_Res_t
00600 nic_set_hostname
00601 ( NLH_t nh,
00602 char *hostname
00603 );
00604
00605 extern
00606 NIC_Res_t
00607 nic_configure
00608 (
00609 NLH_t nh,
00610 NIC_t nic,
00611 IPaddr_list_t *addresses,
00612 IProute_list_t *routes,
00613 IPaddr_list_t *dns_servers,
00614 char *search_list,
00615 char *host_name
00616 );
00617
00618 #endif