18626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma/*
28626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma * Copyright (C) 2011 The Android Open Source Project
38626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma *
48626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma * Licensed under the Apache License, Version 2.0 (the "License");
58626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma * you may not use this file except in compliance with the License.
68626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma * You may obtain a copy of the License at
78626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma *
88626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma *      http://www.apache.org/licenses/LICENSE-2.0
98626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma *
108626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma * Unless required by applicable law or agreed to in writing, software
118626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma * distributed under the License is distributed on an "AS IS" BASIS,
128626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
138626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma * See the License for the specific language governing permissions and
148626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma * limitations under the License.
158626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma */
168626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma
178626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma#ifndef __CUTILS_QTAGUID_H
188626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma#define __CUTILS_QTAGUID_H
198626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma
208626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma#include <stdint.h>
218626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma#include <sys/types.h>
226dce8322d66361e40d1feb5a6c3de15244de5949Ashish Sharma#include <unistd.h>
238626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma
248626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma#ifdef __cplusplus
258626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharmaextern "C" {
268626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma#endif
278626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma
288626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma/*
298626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma * Set tags (and owning UIDs) for network sockets.
308626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma*/
319b5c774369fcbd4460751f9b01e692d688c386baAshish Sharmaextern int qtaguid_tagSocket(int sockfd, int tag, uid_t uid);
329b5c774369fcbd4460751f9b01e692d688c386baAshish Sharma
339b5c774369fcbd4460751f9b01e692d688c386baAshish Sharma/*
349b5c774369fcbd4460751f9b01e692d688c386baAshish Sharma * Untag a network socket before closing.
359b5c774369fcbd4460751f9b01e692d688c386baAshish Sharma*/
369b5c774369fcbd4460751f9b01e692d688c386baAshish Sharmaextern int qtaguid_untagSocket(int sockfd);
378626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma
38243123fb41d7d2981116bd5d11ba168b127d68e9JP Abgrall/*
39243123fb41d7d2981116bd5d11ba168b127d68e9JP Abgrall * For the given uid, switch counter sets.
40243123fb41d7d2981116bd5d11ba168b127d68e9JP Abgrall * The kernel only keeps a limited number of sets.
41243123fb41d7d2981116bd5d11ba168b127d68e9JP Abgrall * 2 for now.
42243123fb41d7d2981116bd5d11ba168b127d68e9JP Abgrall */
43243123fb41d7d2981116bd5d11ba168b127d68e9JP Abgrallextern int qtaguid_setCounterSet(int counterSetNum, uid_t uid);
44243123fb41d7d2981116bd5d11ba168b127d68e9JP Abgrall
45243123fb41d7d2981116bd5d11ba168b127d68e9JP Abgrall/*
46243123fb41d7d2981116bd5d11ba168b127d68e9JP Abgrall * Delete all tag info that relates to the given tag an uid.
47243123fb41d7d2981116bd5d11ba168b127d68e9JP Abgrall * If the tag is 0, then ALL info about the uid is freeded.
48243123fb41d7d2981116bd5d11ba168b127d68e9JP Abgrall * The delete data also affects active tagged socketd, which are
49243123fb41d7d2981116bd5d11ba168b127d68e9JP Abgrall * then untagged.
50243123fb41d7d2981116bd5d11ba168b127d68e9JP Abgrall * The calling process can only operate on its own tags.
51243123fb41d7d2981116bd5d11ba168b127d68e9JP Abgrall * Unless it is part of the happy AID_NET_BW_ACCT group.
52243123fb41d7d2981116bd5d11ba168b127d68e9JP Abgrall * In which case it can clobber everything.
53243123fb41d7d2981116bd5d11ba168b127d68e9JP Abgrall */
54243123fb41d7d2981116bd5d11ba168b127d68e9JP Abgrallextern int qtaguid_deleteTagData(int tag, uid_t uid);
55243123fb41d7d2981116bd5d11ba168b127d68e9JP Abgrall
56243123fb41d7d2981116bd5d11ba168b127d68e9JP Abgrall/*
57243123fb41d7d2981116bd5d11ba168b127d68e9JP Abgrall * Enable/disable qtaguid functionnality at a lower level.
58243123fb41d7d2981116bd5d11ba168b127d68e9JP Abgrall * When pacified, the kernel will accept commands but do nothing.
59243123fb41d7d2981116bd5d11ba168b127d68e9JP Abgrall */
60243123fb41d7d2981116bd5d11ba168b127d68e9JP Abgrallextern int qtaguid_setPacifier(int on);
61243123fb41d7d2981116bd5d11ba168b127d68e9JP Abgrall
628626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma#ifdef __cplusplus
638626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma}
648626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma#endif
658626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma
668626cce5f381899f47e3a82e2ef4c98f183391b0Ashish Sharma#endif /* __CUTILS_QTAG_UID_H */
67