class DestinationMapper extends AddressMapper {
private static final Logger LOG = LoggerFactory.getLogger(DestinationMapper.class);
- private static final String METADATA_IP_PREFIX = "169.254.169.254/32";
- private static final String IN__METADATA = "In__METADATA";
DestinationMapper(ACE_DIRECTION direction) {
super(direction);
@Override
void updateRule(AddressEndpointWithLocation addrEp, GbpAceBuilder aclRuleBuilder) {
- if (!EndpointUtils.getParentEndpoints(addrEp.getParentEndpointChoice()).isEmpty()) {
- // TODO more parents, when supported
+ String address;
+ if (addrEp.getContextType().isAssignableFrom(L3Context.class)) {
+ address = addrEp.getAddress();
+ } else {
ParentEndpoint parentEp = EndpointUtils.getParentEndpoints(addrEp.getParentEndpointChoice()).get(0);
- if (parentEp != null && parentEp.getContextType().isAssignableFrom(L3Context.class)) {
- // TODO this is a fix for metadata agent in DHCP namespace, when we will fully support multiple IPs
- // per interface we shall rework this
- if (aclRuleBuilder.getName().contains(IN__METADATA)) {
- LOG.trace("Setting dst IP address {} in rule {}", METADATA_IP_PREFIX, aclRuleBuilder);
- try {
- AccessListUtil.setDestinationL3Address(aclRuleBuilder, METADATA_IP_PREFIX);
- } catch (UnknownHostException e) {
- LOG.error("Failed to parse address {}. Cannot apply ACL entry {}. {}", METADATA_IP_PREFIX,
- aclRuleBuilder, e);
- }
- } else {
- LOG.trace("Setting dst IP address {} in rule {}", parentEp.getAddress(), aclRuleBuilder);
- try {
- AccessListUtil.setDestinationL3Address(aclRuleBuilder, parentEp.getAddress());
- } catch (UnknownHostException e) {
- LOG.error("Failed to parse address {}. Cannot apply ACL entry {}. {}", parentEp.getAddress(),
- aclRuleBuilder, e);
- }
- }
-
+ if (parentEp == null || !parentEp.getContextType().isAssignableFrom(L3Context.class)) {
+ LOG.warn("Cannot resolve IP address for endpoint {}", addrEp);
+ return;
}
+ address = parentEp.getAddress();
+ }
+ LOG.trace("Setting dst IP address {} in rule {}", address, aclRuleBuilder);
+ try {
+ AccessListUtil.setDestinationL3Address(aclRuleBuilder, address);
+ } catch (UnknownHostException e) {
+ LOG.error("Failed to parse address {}. Cannot apply ACL entry {}. {}", address, aclRuleBuilder, e);
}
}
}