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