]>
Commit | Line | Data |
---|---|---|
ba59486f TB |
1 | /* |
2 | * Copyright (C) 2013 Tobias Brunner | |
3 | * Copyright (C) 2012 Christoph Buehler | |
4 | * Copyright (C) 2012 Patrick Loetscher | |
19ef2aec TB |
5 | * |
6 | * Copyright (C) secunet Security Networks AG | |
ba59486f TB |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify it | |
9 | * under the terms of the GNU General Public License as published by the | |
10 | * Free Software Foundation; either version 2 of the License, or (at your | |
11 | * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, but | |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | |
15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 | * for more details. | |
17 | */ | |
18 | ||
19 | package org.strongswan.android.logic.imc.attributes; | |
20 | ||
21 | import java.util.LinkedList; | |
22 | ||
23 | import org.strongswan.android.logic.imc.collectors.Protocol; | |
24 | import org.strongswan.android.utils.BufferedByteWriter; | |
25 | ||
26 | import android.util.Pair; | |
27 | ||
28 | /** | |
29 | * PA-TNC Port Filter attribute (see section 4.2.6 of RFC 5792) | |
30 | * | |
31 | * 1 2 3 | |
32 | * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | |
33 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
34 | * | Reserved |B| Protocol | Port Number | | |
35 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
36 | * | Reserved |B| Protocol | Port Number | | |
37 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
38 | */ | |
39 | public class PortFilterAttribute implements Attribute | |
40 | { | |
41 | private final LinkedList<Pair<Protocol, Short>> mPorts = new LinkedList<Pair<Protocol, Short>>(); | |
42 | ||
43 | /** | |
44 | * Add an open port with the given protocol and port number | |
45 | * @param protocol transport protocol | |
46 | * @param port port number | |
47 | */ | |
48 | public void addPort(Protocol protocol, short port) | |
49 | { | |
50 | mPorts.add(new Pair<Protocol, Short>(protocol, port)); | |
51 | } | |
52 | ||
53 | @Override | |
54 | public byte[] getEncoding() | |
55 | { | |
56 | BufferedByteWriter writer = new BufferedByteWriter(); | |
57 | for (Pair<Protocol, Short> port : mPorts) | |
58 | { | |
59 | /* we report open ports, so the BLOCKED flag is not set */ | |
60 | writer.put((byte)0); | |
61 | writer.put(port.first.getValue()); | |
62 | writer.put16(port.second); | |
63 | } | |
64 | return writer.toByteArray(); | |
65 | } | |
66 | } |