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