Iran is having a good war. If Iran and Iraq were the two losers of their 1980-1988 war, and all their enemies gainers, Iran is the principal winner of the current conflict in the Persian Gulf. To begin with, Iraq settled the 1980 dispute on Iran's terms, to demilitarize their border and free the Iraqi troops there to face the Americans to the south. Then Iran retrieved its prisoners from the hardship of Iraqi camps in their overdue prisoner exchange.
More than that, Iran sees its two enemies destroying each other. Its own weakened state gains security from the degradation of Iraq's military machine. Any rebuke to American power would be satisfying to the Islamic regime in Tehran, which would dread an overwhelming victory for either side. Either the enlargement of Saddam Hussein's mystique or American power unchallenged in the gulf would intimidate Tehran. If Iran is tricky on the sidelines, that is reminiscent of the American role in the Iran-Iraq war, which was to help the loser of the moment, Iraq overtly and Iran covertly.
But the principal opportunity for Iran's relatively pragmatic rulers is to use the conflict to restore Iran's standing in the community of nations. Whatever the truth behind the flight of Iraqi warplanes to sanctuary in Iran, the need of both Iraq and coalition members to talk about their status helps end Iran's isolation. The use of the long border to thwart United Nations trade sanctions helps Iraq, but would not harm the U.S. if limited to humanitarian needs of food and medicine.