]>
Commit | Line | Data |
---|---|---|
a3bcde70 HT |
1 | /** @file\r |
2 | The implementation of match policy entry function in IpSecConfig application.\r | |
3 | \r | |
22441982 | 4 | Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.<BR>\r |
a3bcde70 HT |
5 | \r |
6 | This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php.\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #include "IpSecConfig.h"\r | |
17 | #include "Indexer.h"\r | |
18 | #include "Match.h"\r | |
19 | \r | |
20 | /**\r | |
21 | Private function to validate a buffer that should be filled with zero.\r | |
22 | \r | |
23 | @param[in] Memory The pointer to the buffer.\r | |
24 | @param[in] Size The size of the buffer.\r | |
25 | \r | |
26 | @retval TRUE The memory is filled with zero.\r | |
27 | @retval FALSE The memory isn't filled with zero.\r | |
28 | **/\r | |
29 | BOOLEAN\r | |
30 | IsMemoryZero (\r | |
31 | IN VOID *Memory,\r | |
32 | IN UINTN Size\r | |
33 | )\r | |
34 | {\r | |
35 | UINTN Index;\r | |
36 | \r | |
37 | for (Index = 0; Index < Size; Index++) {\r | |
38 | if (*((UINT8 *) Memory + Index) != 0) {\r | |
39 | return FALSE;\r | |
40 | }\r | |
41 | }\r | |
42 | \r | |
43 | return TRUE;\r | |
44 | }\r | |
45 | \r | |
46 | /**\r | |
47 | Find the matching SPD with Indexer.\r | |
48 | \r | |
49 | @param[in] Selector The pointer to the EFI_IPSEC_SPD_SELECTOR structure.\r | |
50 | @param[in] Data The pointer to the EFI_IPSEC_SPD_DATA structure.\r | |
51 | @param[in] Indexer The pointer to the SPD_ENTRY_INDEXER structure.\r | |
52 | \r | |
53 | @retval TRUE The matched SPD is found.\r | |
54 | @retval FALSE The matched SPD is not found.\r | |
55 | **/\r | |
56 | BOOLEAN\r | |
57 | MatchSpdEntry (\r | |
58 | IN EFI_IPSEC_SPD_SELECTOR *Selector,\r | |
59 | IN EFI_IPSEC_SPD_DATA *Data,\r | |
60 | IN SPD_ENTRY_INDEXER *Indexer\r | |
61 | )\r | |
62 | {\r | |
63 | BOOLEAN Match;\r | |
64 | \r | |
65 | Match = FALSE;\r | |
66 | if (Indexer->Name != NULL) {\r | |
67 | if ((Data->Name != NULL) && (AsciiStrCmp ((CHAR8 *) Indexer->Name, (CHAR8 *) Data->Name) == 0)) {\r | |
68 | Match = TRUE;\r | |
69 | }\r | |
70 | } else {\r | |
71 | if (Indexer->Index == 0) {\r | |
72 | Match = TRUE;\r | |
73 | }\r | |
74 | \r | |
75 | Indexer->Index--;\r | |
76 | }\r | |
77 | \r | |
78 | return Match;\r | |
79 | }\r | |
80 | \r | |
81 | /**\r | |
82 | Find the matching SAD with Indexer.\r | |
83 | \r | |
84 | @param[in] SaId The pointer to the EFI_IPSEC_SA_ID structure.\r | |
22441982 | 85 | @param[in] Data The pointer to the EFI_IPSEC_SA_DATA2 structure.\r |
a3bcde70 HT |
86 | @param[in] Indexer The pointer to the SPD_ENTRY_INDEXER structure.\r |
87 | \r | |
88 | @retval TRUE The matched SAD is found.\r | |
89 | @retval FALSE The matched SAD is not found.\r | |
90 | **/\r | |
91 | BOOLEAN\r | |
92 | MatchSadEntry (\r | |
93 | IN EFI_IPSEC_SA_ID *SaId,\r | |
64b2d0e5 | 94 | IN EFI_IPSEC_SA_DATA2 *Data,\r |
a3bcde70 HT |
95 | IN SAD_ENTRY_INDEXER *Indexer\r |
96 | )\r | |
97 | {\r | |
98 | BOOLEAN Match;\r | |
99 | \r | |
100 | Match = FALSE;\r | |
101 | if (!IsMemoryZero (&Indexer->SaId, sizeof (EFI_IPSEC_SA_ID))) {\r | |
102 | Match = (BOOLEAN) (CompareMem (&Indexer->SaId, SaId, sizeof (EFI_IPSEC_SA_ID)) == 0);\r | |
103 | } else {\r | |
104 | if (Indexer->Index == 0) {\r | |
105 | Match = TRUE;\r | |
106 | }\r | |
107 | Indexer->Index--;\r | |
108 | }\r | |
109 | \r | |
110 | return Match;\r | |
111 | }\r | |
112 | \r | |
113 | /**\r | |
114 | Find the matching PAD with Indexer.\r | |
115 | \r | |
116 | @param[in] PadId The pointer to the EFI_IPSEC_PAD_ID structure.\r | |
117 | @param[in] Data The pointer to the EFI_IPSEC_PAD_DATA structure.\r | |
118 | @param[in] Indexer The pointer to the SPD_ENTRY_INDEXER structure.\r | |
119 | \r | |
120 | @retval TRUE The matched PAD is found.\r | |
121 | @retval FALSE The matched PAD is not found.\r | |
122 | **/\r | |
123 | BOOLEAN\r | |
124 | MatchPadEntry (\r | |
125 | IN EFI_IPSEC_PAD_ID *PadId,\r | |
126 | IN EFI_IPSEC_PAD_DATA *Data,\r | |
127 | IN PAD_ENTRY_INDEXER *Indexer\r | |
128 | )\r | |
129 | {\r | |
130 | BOOLEAN Match;\r | |
131 | \r | |
132 | Match = FALSE;\r | |
133 | if (!IsMemoryZero (&Indexer->PadId, sizeof (EFI_IPSEC_PAD_ID))) {\r | |
134 | Match = (BOOLEAN) ((Indexer->PadId.PeerIdValid == PadId->PeerIdValid) &&\r | |
135 | ((PadId->PeerIdValid &&\r | |
136 | (StrCmp (\r | |
137 | (CONST CHAR16 *) Indexer->PadId.Id.PeerId,\r | |
138 | (CONST CHAR16 *) PadId->Id.PeerId\r | |
139 | ) == 0)) ||\r | |
140 | ((!PadId->PeerIdValid) &&\r | |
141 | (Indexer->PadId.Id.IpAddress.PrefixLength == PadId->Id.IpAddress.PrefixLength) &&\r | |
142 | (CompareMem (\r | |
143 | &Indexer->PadId.Id.IpAddress.Address,\r | |
144 | &PadId->Id.IpAddress.Address,\r | |
145 | sizeof (EFI_IP_ADDRESS)\r | |
146 | ) == 0))));\r | |
147 | } else {\r | |
148 | if (Indexer->Index == 0) {\r | |
149 | Match = TRUE;\r | |
150 | }\r | |
151 | \r | |
152 | Indexer->Index--;\r | |
153 | }\r | |
154 | \r | |
155 | return Match;\r | |
156 | }\r | |
157 | \r | |
158 | MATCH_POLICY_ENTRY mMatchPolicyEntry[] = {\r | |
159 | (MATCH_POLICY_ENTRY) MatchSpdEntry,\r | |
160 | (MATCH_POLICY_ENTRY) MatchSadEntry,\r | |
161 | (MATCH_POLICY_ENTRY) MatchPadEntry\r | |
162 | };\r | |
163 | \r |