netlabel_kapi.c (cb72d38211eacda2dd90b09540542b6582da614e) netlabel_kapi.c (3faa8f982f958961fda68b8d63e682fe77a032d4)
1/*
2 * NetLabel Kernel API
3 *
4 * This file defines the kernel API for the NetLabel system. The NetLabel
5 * system manages static and dynamic label mappings for network protocols such
6 * as CIPSO and RIPSO.
7 *
8 * Author: Paul Moore <paul@paul-moore.com>

--- 714 unchanged lines hidden (view full) ---

723
724 offset -= iter->startbit;
725 idx = offset / NETLBL_CATMAP_MAPSIZE;
726 iter->bitmap[idx] |= bitmap << (offset % NETLBL_CATMAP_MAPSIZE);
727
728 return 0;
729}
730
1/*
2 * NetLabel Kernel API
3 *
4 * This file defines the kernel API for the NetLabel system. The NetLabel
5 * system manages static and dynamic label mappings for network protocols such
6 * as CIPSO and RIPSO.
7 *
8 * Author: Paul Moore <paul@paul-moore.com>

--- 714 unchanged lines hidden (view full) ---

723
724 offset -= iter->startbit;
725 idx = offset / NETLBL_CATMAP_MAPSIZE;
726 iter->bitmap[idx] |= bitmap << (offset % NETLBL_CATMAP_MAPSIZE);
727
728 return 0;
729}
730
731/* Bitmap functions
732 */
733
734/**
735 * netlbl_bitmap_walk - Walk a bitmap looking for a bit
736 * @bitmap: the bitmap
737 * @bitmap_len: length in bits
738 * @offset: starting offset
739 * @state: if non-zero, look for a set (1) bit else look for a cleared (0) bit
740 *
741 * Description:
742 * Starting at @offset, walk the bitmap from left to right until either the
743 * desired bit is found or we reach the end. Return the bit offset, -1 if
744 * not found, or -2 if error.
745 */
746int netlbl_bitmap_walk(const unsigned char *bitmap, u32 bitmap_len,
747 u32 offset, u8 state)
748{
749 u32 bit_spot;
750 u32 byte_offset;
751 unsigned char bitmask;
752 unsigned char byte;
753
754 byte_offset = offset / 8;
755 byte = bitmap[byte_offset];
756 bit_spot = offset;
757 bitmask = 0x80 >> (offset % 8);
758
759 while (bit_spot < bitmap_len) {
760 if ((state && (byte & bitmask) == bitmask) ||
761 (state == 0 && (byte & bitmask) == 0))
762 return bit_spot;
763
764 bit_spot++;
765 bitmask >>= 1;
766 if (bitmask == 0) {
767 byte = bitmap[++byte_offset];
768 bitmask = 0x80;
769 }
770 }
771
772 return -1;
773}
774EXPORT_SYMBOL(netlbl_bitmap_walk);
775
776/**
777 * netlbl_bitmap_setbit - Sets a single bit in a bitmap
778 * @bitmap: the bitmap
779 * @bit: the bit
780 * @state: if non-zero, set the bit (1) else clear the bit (0)
781 *
782 * Description:
783 * Set a single bit in the bitmask. Returns zero on success, negative values
784 * on error.
785 */
786void netlbl_bitmap_setbit(unsigned char *bitmap, u32 bit, u8 state)
787{
788 u32 byte_spot;
789 u8 bitmask;
790
791 /* gcc always rounds to zero when doing integer division */
792 byte_spot = bit / 8;
793 bitmask = 0x80 >> (bit % 8);
794 if (state)
795 bitmap[byte_spot] |= bitmask;
796 else
797 bitmap[byte_spot] &= ~bitmask;
798}
799EXPORT_SYMBOL(netlbl_bitmap_setbit);
800
731/*
732 * LSM Functions
733 */
734
735/**
736 * netlbl_enabled - Determine if the NetLabel subsystem is enabled
737 *
738 * Description:

--- 483 unchanged lines hidden ---
801/*
802 * LSM Functions
803 */
804
805/**
806 * netlbl_enabled - Determine if the NetLabel subsystem is enabled
807 *
808 * Description:

--- 483 unchanged lines hidden ---