0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef _NETLABEL_H
0016 #define _NETLABEL_H
0017
0018 #include <linux/types.h>
0019 #include <linux/slab.h>
0020 #include <linux/net.h>
0021 #include <linux/skbuff.h>
0022 #include <linux/in.h>
0023 #include <linux/in6.h>
0024 #include <net/netlink.h>
0025 #include <net/request_sock.h>
0026 #include <linux/refcount.h>
0027
0028 struct cipso_v4_doi;
0029 struct calipso_doi;
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068 #define NETLBL_PROTO_VERSION 3
0069
0070
0071 #define NETLBL_NLTYPE_NONE 0
0072 #define NETLBL_NLTYPE_MGMT 1
0073 #define NETLBL_NLTYPE_MGMT_NAME "NLBL_MGMT"
0074 #define NETLBL_NLTYPE_RIPSO 2
0075 #define NETLBL_NLTYPE_RIPSO_NAME "NLBL_RIPSO"
0076 #define NETLBL_NLTYPE_CIPSOV4 3
0077 #define NETLBL_NLTYPE_CIPSOV4_NAME "NLBL_CIPSOv4"
0078 #define NETLBL_NLTYPE_CIPSOV6 4
0079 #define NETLBL_NLTYPE_CIPSOV6_NAME "NLBL_CIPSOv6"
0080 #define NETLBL_NLTYPE_UNLABELED 5
0081 #define NETLBL_NLTYPE_UNLABELED_NAME "NLBL_UNLBL"
0082 #define NETLBL_NLTYPE_ADDRSELECT 6
0083 #define NETLBL_NLTYPE_ADDRSELECT_NAME "NLBL_ADRSEL"
0084 #define NETLBL_NLTYPE_CALIPSO 7
0085 #define NETLBL_NLTYPE_CALIPSO_NAME "NLBL_CALIPSO"
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099 struct netlbl_audit {
0100 u32 secid;
0101 kuid_t loginuid;
0102 unsigned int sessionid;
0103 };
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124 struct netlbl_lsm_cache {
0125 refcount_t refcount;
0126 void (*free) (const void *data);
0127 void *data;
0128 };
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148 #define NETLBL_CATMAP_MAPTYPE u64
0149 #define NETLBL_CATMAP_MAPCNT 4
0150 #define NETLBL_CATMAP_MAPSIZE (sizeof(NETLBL_CATMAP_MAPTYPE) * 8)
0151 #define NETLBL_CATMAP_SIZE (NETLBL_CATMAP_MAPSIZE * \
0152 NETLBL_CATMAP_MAPCNT)
0153 #define NETLBL_CATMAP_BIT (NETLBL_CATMAP_MAPTYPE)0x01
0154 struct netlbl_lsm_catmap {
0155 u32 startbit;
0156 NETLBL_CATMAP_MAPTYPE bitmap[NETLBL_CATMAP_MAPCNT];
0157 struct netlbl_lsm_catmap *next;
0158 };
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180 struct netlbl_lsm_secattr {
0181 u32 flags;
0182
0183 #define NETLBL_SECATTR_NONE 0x00000000
0184 #define NETLBL_SECATTR_DOMAIN 0x00000001
0185 #define NETLBL_SECATTR_DOMAIN_CPY (NETLBL_SECATTR_DOMAIN | \
0186 NETLBL_SECATTR_FREE_DOMAIN)
0187 #define NETLBL_SECATTR_CACHE 0x00000002
0188 #define NETLBL_SECATTR_MLS_LVL 0x00000004
0189 #define NETLBL_SECATTR_MLS_CAT 0x00000008
0190 #define NETLBL_SECATTR_SECID 0x00000010
0191
0192 #define NETLBL_SECATTR_FREE_DOMAIN 0x01000000
0193 #define NETLBL_SECATTR_CACHEABLE (NETLBL_SECATTR_MLS_LVL | \
0194 NETLBL_SECATTR_MLS_CAT | \
0195 NETLBL_SECATTR_SECID)
0196 u32 type;
0197 char *domain;
0198 struct netlbl_lsm_cache *cache;
0199 struct {
0200 struct {
0201 struct netlbl_lsm_catmap *cat;
0202 u32 lvl;
0203 } mls;
0204 u32 secid;
0205 } attr;
0206 };
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233 struct netlbl_calipso_ops {
0234 int (*doi_add)(struct calipso_doi *doi_def,
0235 struct netlbl_audit *audit_info);
0236 void (*doi_free)(struct calipso_doi *doi_def);
0237 int (*doi_remove)(u32 doi, struct netlbl_audit *audit_info);
0238 struct calipso_doi *(*doi_getdef)(u32 doi);
0239 void (*doi_putdef)(struct calipso_doi *doi_def);
0240 int (*doi_walk)(u32 *skip_cnt,
0241 int (*callback)(struct calipso_doi *doi_def, void *arg),
0242 void *cb_arg);
0243 int (*sock_getattr)(struct sock *sk,
0244 struct netlbl_lsm_secattr *secattr);
0245 int (*sock_setattr)(struct sock *sk,
0246 const struct calipso_doi *doi_def,
0247 const struct netlbl_lsm_secattr *secattr);
0248 void (*sock_delattr)(struct sock *sk);
0249 int (*req_setattr)(struct request_sock *req,
0250 const struct calipso_doi *doi_def,
0251 const struct netlbl_lsm_secattr *secattr);
0252 void (*req_delattr)(struct request_sock *req);
0253 int (*opt_getattr)(const unsigned char *calipso,
0254 struct netlbl_lsm_secattr *secattr);
0255 unsigned char *(*skbuff_optptr)(const struct sk_buff *skb);
0256 int (*skbuff_setattr)(struct sk_buff *skb,
0257 const struct calipso_doi *doi_def,
0258 const struct netlbl_lsm_secattr *secattr);
0259 int (*skbuff_delattr)(struct sk_buff *skb);
0260 void (*cache_invalidate)(void);
0261 int (*cache_add)(const unsigned char *calipso_ptr,
0262 const struct netlbl_lsm_secattr *secattr);
0263 };
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278 static inline struct netlbl_lsm_cache *netlbl_secattr_cache_alloc(gfp_t flags)
0279 {
0280 struct netlbl_lsm_cache *cache;
0281
0282 cache = kzalloc(sizeof(*cache), flags);
0283 if (cache)
0284 refcount_set(&cache->refcount, 1);
0285 return cache;
0286 }
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296 static inline void netlbl_secattr_cache_free(struct netlbl_lsm_cache *cache)
0297 {
0298 if (!refcount_dec_and_test(&cache->refcount))
0299 return;
0300
0301 if (cache->free)
0302 cache->free(cache->data);
0303 kfree(cache);
0304 }
0305
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315 static inline struct netlbl_lsm_catmap *netlbl_catmap_alloc(gfp_t flags)
0316 {
0317 return kzalloc(sizeof(struct netlbl_lsm_catmap), flags);
0318 }
0319
0320
0321
0322
0323
0324
0325
0326
0327
0328 static inline void netlbl_catmap_free(struct netlbl_lsm_catmap *catmap)
0329 {
0330 struct netlbl_lsm_catmap *iter;
0331
0332 while (catmap) {
0333 iter = catmap;
0334 catmap = catmap->next;
0335 kfree(iter);
0336 }
0337 }
0338
0339
0340
0341
0342
0343
0344
0345
0346
0347 static inline void netlbl_secattr_init(struct netlbl_lsm_secattr *secattr)
0348 {
0349 memset(secattr, 0, sizeof(*secattr));
0350 }
0351
0352
0353
0354
0355
0356
0357
0358
0359
0360
0361 static inline void netlbl_secattr_destroy(struct netlbl_lsm_secattr *secattr)
0362 {
0363 if (secattr->flags & NETLBL_SECATTR_FREE_DOMAIN)
0364 kfree(secattr->domain);
0365 if (secattr->flags & NETLBL_SECATTR_CACHE)
0366 netlbl_secattr_cache_free(secattr->cache);
0367 if (secattr->flags & NETLBL_SECATTR_MLS_CAT)
0368 netlbl_catmap_free(secattr->attr.mls.cat);
0369 }
0370
0371
0372
0373
0374
0375
0376
0377
0378
0379
0380 static inline struct netlbl_lsm_secattr *netlbl_secattr_alloc(gfp_t flags)
0381 {
0382 return kzalloc(sizeof(struct netlbl_lsm_secattr), flags);
0383 }
0384
0385
0386
0387
0388
0389
0390
0391
0392
0393 static inline void netlbl_secattr_free(struct netlbl_lsm_secattr *secattr)
0394 {
0395 netlbl_secattr_destroy(secattr);
0396 kfree(secattr);
0397 }
0398
0399 #ifdef CONFIG_NETLABEL
0400
0401
0402
0403 int netlbl_cfg_map_del(const char *domain,
0404 u16 family,
0405 const void *addr,
0406 const void *mask,
0407 struct netlbl_audit *audit_info);
0408 int netlbl_cfg_unlbl_map_add(const char *domain,
0409 u16 family,
0410 const void *addr,
0411 const void *mask,
0412 struct netlbl_audit *audit_info);
0413 int netlbl_cfg_unlbl_static_add(struct net *net,
0414 const char *dev_name,
0415 const void *addr,
0416 const void *mask,
0417 u16 family,
0418 u32 secid,
0419 struct netlbl_audit *audit_info);
0420 int netlbl_cfg_unlbl_static_del(struct net *net,
0421 const char *dev_name,
0422 const void *addr,
0423 const void *mask,
0424 u16 family,
0425 struct netlbl_audit *audit_info);
0426 int netlbl_cfg_cipsov4_add(struct cipso_v4_doi *doi_def,
0427 struct netlbl_audit *audit_info);
0428 void netlbl_cfg_cipsov4_del(u32 doi, struct netlbl_audit *audit_info);
0429 int netlbl_cfg_cipsov4_map_add(u32 doi,
0430 const char *domain,
0431 const struct in_addr *addr,
0432 const struct in_addr *mask,
0433 struct netlbl_audit *audit_info);
0434 int netlbl_cfg_calipso_add(struct calipso_doi *doi_def,
0435 struct netlbl_audit *audit_info);
0436 void netlbl_cfg_calipso_del(u32 doi, struct netlbl_audit *audit_info);
0437 int netlbl_cfg_calipso_map_add(u32 doi,
0438 const char *domain,
0439 const struct in6_addr *addr,
0440 const struct in6_addr *mask,
0441 struct netlbl_audit *audit_info);
0442
0443
0444
0445 int netlbl_catmap_walk(struct netlbl_lsm_catmap *catmap, u32 offset);
0446 int netlbl_catmap_walkrng(struct netlbl_lsm_catmap *catmap, u32 offset);
0447 int netlbl_catmap_getlong(struct netlbl_lsm_catmap *catmap,
0448 u32 *offset,
0449 unsigned long *bitmap);
0450 int netlbl_catmap_setbit(struct netlbl_lsm_catmap **catmap,
0451 u32 bit,
0452 gfp_t flags);
0453 int netlbl_catmap_setrng(struct netlbl_lsm_catmap **catmap,
0454 u32 start,
0455 u32 end,
0456 gfp_t flags);
0457 int netlbl_catmap_setlong(struct netlbl_lsm_catmap **catmap,
0458 u32 offset,
0459 unsigned long bitmap,
0460 gfp_t flags);
0461
0462
0463
0464 int netlbl_bitmap_walk(const unsigned char *bitmap, u32 bitmap_len,
0465 u32 offset, u8 state);
0466 void netlbl_bitmap_setbit(unsigned char *bitmap, u32 bit, u8 state);
0467
0468
0469
0470
0471 int netlbl_enabled(void);
0472 int netlbl_sock_setattr(struct sock *sk,
0473 u16 family,
0474 const struct netlbl_lsm_secattr *secattr);
0475 void netlbl_sock_delattr(struct sock *sk);
0476 int netlbl_sock_getattr(struct sock *sk,
0477 struct netlbl_lsm_secattr *secattr);
0478 int netlbl_conn_setattr(struct sock *sk,
0479 struct sockaddr *addr,
0480 const struct netlbl_lsm_secattr *secattr);
0481 int netlbl_req_setattr(struct request_sock *req,
0482 const struct netlbl_lsm_secattr *secattr);
0483 void netlbl_req_delattr(struct request_sock *req);
0484 int netlbl_skbuff_setattr(struct sk_buff *skb,
0485 u16 family,
0486 const struct netlbl_lsm_secattr *secattr);
0487 int netlbl_skbuff_getattr(const struct sk_buff *skb,
0488 u16 family,
0489 struct netlbl_lsm_secattr *secattr);
0490 void netlbl_skbuff_err(struct sk_buff *skb, u16 family, int error, int gateway);
0491
0492
0493
0494
0495 void netlbl_cache_invalidate(void);
0496 int netlbl_cache_add(const struct sk_buff *skb, u16 family,
0497 const struct netlbl_lsm_secattr *secattr);
0498
0499
0500
0501
0502 struct audit_buffer *netlbl_audit_start(int type,
0503 struct netlbl_audit *audit_info);
0504 #else
0505 static inline int netlbl_cfg_map_del(const char *domain,
0506 u16 family,
0507 const void *addr,
0508 const void *mask,
0509 struct netlbl_audit *audit_info)
0510 {
0511 return -ENOSYS;
0512 }
0513 static inline int netlbl_cfg_unlbl_map_add(const char *domain,
0514 u16 family,
0515 void *addr,
0516 void *mask,
0517 struct netlbl_audit *audit_info)
0518 {
0519 return -ENOSYS;
0520 }
0521 static inline int netlbl_cfg_unlbl_static_add(struct net *net,
0522 const char *dev_name,
0523 const void *addr,
0524 const void *mask,
0525 u16 family,
0526 u32 secid,
0527 struct netlbl_audit *audit_info)
0528 {
0529 return -ENOSYS;
0530 }
0531 static inline int netlbl_cfg_unlbl_static_del(struct net *net,
0532 const char *dev_name,
0533 const void *addr,
0534 const void *mask,
0535 u16 family,
0536 struct netlbl_audit *audit_info)
0537 {
0538 return -ENOSYS;
0539 }
0540 static inline int netlbl_cfg_cipsov4_add(struct cipso_v4_doi *doi_def,
0541 struct netlbl_audit *audit_info)
0542 {
0543 return -ENOSYS;
0544 }
0545 static inline void netlbl_cfg_cipsov4_del(u32 doi,
0546 struct netlbl_audit *audit_info)
0547 {
0548 return;
0549 }
0550 static inline int netlbl_cfg_cipsov4_map_add(u32 doi,
0551 const char *domain,
0552 const struct in_addr *addr,
0553 const struct in_addr *mask,
0554 struct netlbl_audit *audit_info)
0555 {
0556 return -ENOSYS;
0557 }
0558 static inline int netlbl_cfg_calipso_add(struct calipso_doi *doi_def,
0559 struct netlbl_audit *audit_info)
0560 {
0561 return -ENOSYS;
0562 }
0563 static inline void netlbl_cfg_calipso_del(u32 doi,
0564 struct netlbl_audit *audit_info)
0565 {
0566 return;
0567 }
0568 static inline int netlbl_cfg_calipso_map_add(u32 doi,
0569 const char *domain,
0570 const struct in6_addr *addr,
0571 const struct in6_addr *mask,
0572 struct netlbl_audit *audit_info)
0573 {
0574 return -ENOSYS;
0575 }
0576 static inline int netlbl_catmap_walk(struct netlbl_lsm_catmap *catmap,
0577 u32 offset)
0578 {
0579 return -ENOENT;
0580 }
0581 static inline int netlbl_catmap_walkrng(struct netlbl_lsm_catmap *catmap,
0582 u32 offset)
0583 {
0584 return -ENOENT;
0585 }
0586 static inline int netlbl_catmap_getlong(struct netlbl_lsm_catmap *catmap,
0587 u32 *offset,
0588 unsigned long *bitmap)
0589 {
0590 return 0;
0591 }
0592 static inline int netlbl_catmap_setbit(struct netlbl_lsm_catmap **catmap,
0593 u32 bit,
0594 gfp_t flags)
0595 {
0596 return 0;
0597 }
0598 static inline int netlbl_catmap_setrng(struct netlbl_lsm_catmap **catmap,
0599 u32 start,
0600 u32 end,
0601 gfp_t flags)
0602 {
0603 return 0;
0604 }
0605 static inline int netlbl_catmap_setlong(struct netlbl_lsm_catmap **catmap,
0606 u32 offset,
0607 unsigned long bitmap,
0608 gfp_t flags)
0609 {
0610 return 0;
0611 }
0612 static inline int netlbl_enabled(void)
0613 {
0614 return 0;
0615 }
0616 static inline int netlbl_sock_setattr(struct sock *sk,
0617 u16 family,
0618 const struct netlbl_lsm_secattr *secattr)
0619 {
0620 return -ENOSYS;
0621 }
0622 static inline void netlbl_sock_delattr(struct sock *sk)
0623 {
0624 }
0625 static inline int netlbl_sock_getattr(struct sock *sk,
0626 struct netlbl_lsm_secattr *secattr)
0627 {
0628 return -ENOSYS;
0629 }
0630 static inline int netlbl_conn_setattr(struct sock *sk,
0631 struct sockaddr *addr,
0632 const struct netlbl_lsm_secattr *secattr)
0633 {
0634 return -ENOSYS;
0635 }
0636 static inline int netlbl_req_setattr(struct request_sock *req,
0637 const struct netlbl_lsm_secattr *secattr)
0638 {
0639 return -ENOSYS;
0640 }
0641 static inline void netlbl_req_delattr(struct request_sock *req)
0642 {
0643 return;
0644 }
0645 static inline int netlbl_skbuff_setattr(struct sk_buff *skb,
0646 u16 family,
0647 const struct netlbl_lsm_secattr *secattr)
0648 {
0649 return -ENOSYS;
0650 }
0651 static inline int netlbl_skbuff_getattr(const struct sk_buff *skb,
0652 u16 family,
0653 struct netlbl_lsm_secattr *secattr)
0654 {
0655 return -ENOSYS;
0656 }
0657 static inline void netlbl_skbuff_err(struct sk_buff *skb,
0658 int error,
0659 int gateway)
0660 {
0661 return;
0662 }
0663 static inline void netlbl_cache_invalidate(void)
0664 {
0665 return;
0666 }
0667 static inline int netlbl_cache_add(const struct sk_buff *skb, u16 family,
0668 const struct netlbl_lsm_secattr *secattr)
0669 {
0670 return 0;
0671 }
0672 static inline struct audit_buffer *netlbl_audit_start(int type,
0673 struct netlbl_audit *audit_info)
0674 {
0675 return NULL;
0676 }
0677 #endif
0678
0679 const struct netlbl_calipso_ops *
0680 netlbl_calipso_ops_register(const struct netlbl_calipso_ops *ops);
0681
0682 #endif