| 1 | # Copyright (c) 2017 Fujitsu Limited |
| 2 | # All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | # |
| 16 | # Some parts are based on python-conntrack: |
| 17 | # Copyright (c) 2009-2011,2015 Andrew Grigorev <[email protected]> |
| 18 | # |
| 19 | # Permission is hereby granted, free of charge, to any person obtaining a copy |
| 20 | # of this software and associated documentation files (the "Software"), to deal |
| 21 | # in the Software without restriction, including without limitation the rights |
| 22 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 23 | # copies of the Software, and to permit persons to whom the Software is |
| 24 | # furnished to do so, subject to the following conditions: |
| 25 | # |
| 26 | # The above copyright notice and this permission notice shall be included in |
| 27 | # all copies or substantial portions of the Software. |
| 28 | # |
| 29 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 30 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 31 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 32 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 33 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 34 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 35 | # THE SOFTWARE. |
| 36 | # |
| 37 | |
| 38 | import socket |
| 39 | |
| 40 | |
| 41 | CONNTRACK = 0 |
| 42 | |
| 43 | NFCT_O_PLAIN = 0 |
| 44 | |
| 45 | NFCT_OF_TIME_BIT = 1 |
| 46 | NFCT_OF_TIME = 1 << NFCT_OF_TIME_BIT |
| 47 | |
| 48 | NFCT_Q_DESTROY = 2 |
| 49 | NFCT_Q_FLUSH = 4 |
| 50 | NFCT_Q_DUMP = 5 |
| 51 | NFCT_T_DESTROY_BIT = 2 |
| 52 | NFCT_T_DESTROY = 1 << NFCT_T_DESTROY_BIT |
| 53 | |
| 54 | ATTR_IPV4_SRC = 0 |
| 55 | ATTR_IPV4_DST = 1 |
| 56 | ATTR_IPV6_SRC = 4 |
| 57 | ATTR_IPV6_DST = 5 |
| 58 | ATTR_PORT_SRC = 8 |
| 59 | ATTR_PORT_DST = 9 |
| 60 | ATTR_ICMP_TYPE = 12 |
| 61 | ATTR_ICMP_CODE = 13 |
| 62 | ATTR_ICMP_ID = 14 |
| 63 | ATTR_L3PROTO = 15 |
| 64 | ATTR_L4PROTO = 17 |
| 65 | |
| 66 | NFCT_T_NEW_BIT = 0 |
| 67 | NFCT_T_NEW = 1 << NFCT_T_NEW_BIT |
| 68 | NFCT_T_UPDATE_BIT = 1 |
| 69 | NFCT_T_UPDATE = 1 << NFCT_T_UPDATE_BIT |
| 70 | NFCT_T_DESTROY_BIT = 2 |
| 71 | NFCT_T_DESTROY = 1 << NFCT_T_DESTROY_BIT |
| 72 | |
| 73 | NFCT_T_ALL = NFCT_T_NEW | NFCT_T_UPDATE | NFCT_T_DESTROY |
| 74 | |
| 75 | NFCT_CB_CONTINUE = 1 |
| 76 | NFCT_CB_FAILURE = -1 |
| 77 | |
| 78 | NFNL_SUBSYS_CTNETLINK = 0 |
| 79 | |
| 80 | BUFFER = 1024 |
| 81 | # IPv6 address memory buffer |
| 82 | ADDR_BUFFER_6 = 16 |
| 83 | ADDR_BUFFER_4 = 4 |
| 84 | |
| 85 | IPVERSION_SOCKET = {4: socket.AF_INET, 6: socket.AF_INET6} |
| 86 | IPVERSION_BUFFER = {4: ADDR_BUFFER_4, 6: ADDR_BUFFER_6} |