aboutsummaryrefslogtreecommitdiffstats
path: root/net/netlabel/netlabel_kapi.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/netlabel/netlabel_kapi.c')
-rw-r--r--net/netlabel/netlabel_kapi.c78
1 files changed, 77 insertions, 1 deletions
diff --git a/net/netlabel/netlabel_kapi.c b/net/netlabel/netlabel_kapi.c
index cc8047d1f505..78fc557689b2 100644
--- a/net/netlabel/netlabel_kapi.c
+++ b/net/netlabel/netlabel_kapi.c
@@ -10,7 +10,7 @@
10 */ 10 */
11 11
12/* 12/*
13 * (c) Copyright Hewlett-Packard Development Company, L.P., 2006 13 * (c) Copyright Hewlett-Packard Development Company, L.P., 2006, 2008
14 * 14 *
15 * This program is free software; you can redistribute it and/or modify 15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by 16 * it under the terms of the GNU General Public License as published by
@@ -456,6 +456,20 @@ socket_setattr_return:
456} 456}
457 457
458/** 458/**
459 * netlbl_sock_delattr - Delete all the NetLabel labels on a socket
460 * @sk: the socket
461 *
462 * Description:
463 * Remove all the NetLabel labeling from @sk. The caller is responsible for
464 * ensuring that @sk is locked.
465 *
466 */
467void netlbl_sock_delattr(struct sock *sk)
468{
469 cipso_v4_sock_delattr(sk);
470}
471
472/**
459 * netlbl_sock_getattr - Determine the security attributes of a sock 473 * netlbl_sock_getattr - Determine the security attributes of a sock
460 * @sk: the sock 474 * @sk: the sock
461 * @secattr: the security attributes 475 * @secattr: the security attributes
@@ -473,6 +487,68 @@ int netlbl_sock_getattr(struct sock *sk, struct netlbl_lsm_secattr *secattr)
473} 487}
474 488
475/** 489/**
490 * netlbl_conn_setattr - Label a connected socket using the correct protocol
491 * @sk: the socket to label
492 * @addr: the destination address
493 * @secattr: the security attributes
494 *
495 * Description:
496 * Attach the correct label to the given connected socket using the security
497 * attributes specified in @secattr. The caller is responsible for ensuring
498 * that @sk is locked. Returns zero on success, negative values on failure.
499 *
500 */
501int netlbl_conn_setattr(struct sock *sk,
502 struct sockaddr *addr,
503 const struct netlbl_lsm_secattr *secattr)
504{
505 int ret_val;
506 struct sockaddr_in *addr4;
507 struct netlbl_domaddr4_map *af4_entry;
508
509 rcu_read_lock();
510 switch (addr->sa_family) {
511 case AF_INET:
512 addr4 = (struct sockaddr_in *)addr;
513 af4_entry = netlbl_domhsh_getentry_af4(secattr->domain,
514 addr4->sin_addr.s_addr);
515 if (af4_entry == NULL) {
516 ret_val = -ENOENT;
517 goto conn_setattr_return;
518 }
519 switch (af4_entry->type) {
520 case NETLBL_NLTYPE_CIPSOV4:
521 ret_val = cipso_v4_sock_setattr(sk,
522 af4_entry->type_def.cipsov4,
523 secattr);
524 break;
525 case NETLBL_NLTYPE_UNLABELED:
526 /* just delete the protocols we support for right now
527 * but we could remove other protocols if needed */
528 cipso_v4_sock_delattr(sk);
529 ret_val = 0;
530 break;
531 default:
532 ret_val = -ENOENT;
533 }
534 break;
535#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
536 case AF_INET6:
537 /* since we don't support any IPv6 labeling protocols right
538 * now we can optimize everything away until we do */
539 ret_val = 0;
540 break;
541#endif /* IPv6 */
542 default:
543 ret_val = 0;
544 }
545
546conn_setattr_return:
547 rcu_read_unlock();
548 return ret_val;
549}
550
551/**
476 * netlbl_skbuff_setattr - Label a packet using the correct protocol 552 * netlbl_skbuff_setattr - Label a packet using the correct protocol
477 * @skb: the packet 553 * @skb: the packet
478 * @family: protocol family 554 * @family: protocol family